Example usage for org.apache.commons.lang SystemUtils PATH_SEPARATOR

List of usage examples for org.apache.commons.lang SystemUtils PATH_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils PATH_SEPARATOR.

Prototype

String PATH_SEPARATOR

To view the source code for org.apache.commons.lang SystemUtils PATH_SEPARATOR.

Click Source Link

Document

The path.separator System Property.

Usage

From source file:com.yahoo.flowetl.commons.runner.Main.java

/**
 * Gets some useful runtime info as a map of names -> info.
 *///from   w  w  w .j a  v  a  2s .c  o  m
private static Map<String, Object> getRuntimeInfo() {
    Map<String, Object> sysInfo = new TreeMap<String, Object>();
    StringBuilder jvminfo = new StringBuilder();
    jvminfo.append("Vendor: ");
    jvminfo.append(SystemUtils.JAVA_VENDOR);
    jvminfo.append(", Version: ");
    jvminfo.append(SystemUtils.JAVA_VERSION + " - " + SystemUtils.JAVA_VM_INFO);
    jvminfo.append(", OS: ");
    jvminfo.append(SystemUtils.OS_NAME + " (" + SystemUtils.OS_VERSION + " : " + SystemUtils.OS_ARCH + ")");
    sysInfo.put(WordUtils.capitalizeFully("jvm"), jvminfo.toString());
    sysInfo.put(WordUtils.capitalizeFully("default charset encoding"), DEF_CHAR_SET.name());
    String netAdd = NetUtils.getLocalAddress();
    if (StringUtils.isEmpty(netAdd)) {
        netAdd = "????";
    }
    String localName = NetUtils.getLocalHostName();
    if (StringUtils.isEmpty(localName)) {
        localName = "????";
    }
    sysInfo.put(WordUtils.capitalizeFully("network"), localName + " at ip address " + netAdd);
    String cPath = SystemUtils.JAVA_CLASS_PATH;
    String linesep = StringEscapeUtils.escapeJava(SystemUtils.LINE_SEPARATOR);
    sysInfo.put(WordUtils.capitalizeFully("classpath"), cPath);
    sysInfo.put(WordUtils.capitalizeFully("jvm home"), SystemUtils.JAVA_HOME);
    sysInfo.put(WordUtils.capitalizeFully("jvm tmpdir"), SystemUtils.JAVA_IO_TMPDIR);
    sysInfo.put(WordUtils.capitalizeFully("jvm libpath"), SystemUtils.JAVA_LIBRARY_PATH);
    sysInfo.put(WordUtils.capitalizeFully("line separator"), linesep);
    sysInfo.put(WordUtils.capitalizeFully("path separator"),
            StringEscapeUtils.escapeJava(SystemUtils.PATH_SEPARATOR));
    sysInfo.put(WordUtils.capitalizeFully("user timezone"), SystemUtils.USER_TIMEZONE);
    sysInfo.put(WordUtils.capitalizeFully("user home"), SystemUtils.USER_HOME);
    sysInfo.put(WordUtils.capitalizeFully("user language"), SystemUtils.USER_LANGUAGE);
    sysInfo.put(WordUtils.capitalizeFully("user name"), SystemUtils.USER_NAME);
    return sysInfo;
}

From source file:com.jaeksoft.searchlib.parser.ExternalParser.java

public final static void doParserContent(Parser parser, File tempDir, final IndexDocument sourceDocument,
        final StreamLimiter streamLimiter, final LanguageEnum lang)
        throws IOException, SearchLibException, TransformerConfigurationException, SAXException {
    PrintWriter configWriter = null;
    ByteArrayOutputStream err = null;
    ByteArrayOutputStream out = null;
    try {//ww w.j  a  v  a2  s  . c  om
        // Prepare the files JSON and XML
        Command command = new Command(sourceDocument, streamLimiter, lang);
        File commandFile = new File(tempDir, FILE_PARSER_COMMAND);
        JsonUtils.jsonToFile(command, commandFile);
        File configFile = new File(tempDir, FILE_PARSER_CONFIG);
        configWriter = new PrintWriter(configFile, FILE_PARSER_ENCODING);
        XmlWriter xmlWriter = new XmlWriter(configWriter, FILE_PARSER_ENCODING);
        parser.writeXmlConfig(xmlWriter);
        xmlWriter.endDocument();
        configWriter.close();

        // Execute
        out = new ByteArrayOutputStream();
        err = new ByteArrayOutputStream();
        String classPath = ExecuteUtils.getClassPath();
        if (!StringUtils.isEmpty(ADDITIONAL_CLASSPATH))
            classPath = StringUtils.fastConcat(classPath, SystemUtils.PATH_SEPARATOR, ADDITIONAL_CLASSPATH);
        int statusCode = ExecuteUtils.command(tempDir, "java", classPath, true, out, err, 3600000L,
                ExternalParser.class.getName());
        if (statusCode != 0)
            throw new SearchLibException(err.toString("UTF-8"));
        File fileParserResults = new File(tempDir, FILE_PARSER_RESULTS);
        if (!fileParserResults.exists())
            return;
        Results results = JsonUtils.getObject(fileParserResults, Results.class);
        if (!StringUtils.isEmpty(results.error)) {
            Logging.warn("External parser error: " + err.toString());
            throw new SearchLibException.ExternalParserException(results.error);
        }
        parser.setExternalResults(results);
    } catch (ExecuteException e) {
        if (err != null)
            Logging.error(err.toString("UTF-8"));
        throw e;
    } finally {
        IOUtils.close(configWriter, err, out);
    }
}

From source file:org.apache.cocoon.generation.StatusGenerator.java

private void genVMStatus() throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    startGroup("VM");

    // BEGIN ClassPath
    String classpath = SystemUtils.JAVA_CLASS_PATH;
    if (classpath != null) {
        List paths = new ArrayList();
        StringTokenizer tokenizer = new StringTokenizer(classpath, SystemUtils.PATH_SEPARATOR);
        while (tokenizer.hasMoreTokens()) {
            paths.add(tokenizer.nextToken());
        }//w w w  .j ava  2  s.co  m
        addMultilineValue("classpath", paths);
    }
    // END ClassPath

    // BEGIN CONTEXT CLASSPATH
    String contextClassPath = null;
    try {
        contextClassPath = (String) this.context.get(Constants.CONTEXT_CLASSPATH);
    } catch (ContextException e) {
        // we ignore this
    }
    if (contextClassPath != null) {
        List paths = new ArrayList();
        StringTokenizer tokenizer = new StringTokenizer(contextClassPath, File.pathSeparator);
        while (tokenizer.hasMoreTokens()) {
            paths.add(tokenizer.nextToken());
        }
        addMultilineValue("context-classpath", paths);
    }
    // END CONTEXT CLASSPATH

    // BEGIN Memory status
    startGroup("Memory");
    final long totalMemory = Runtime.getRuntime().totalMemory();
    final long freeMemory = Runtime.getRuntime().freeMemory();
    addValue("total", String.valueOf(totalMemory));
    addValue("used", String.valueOf(totalMemory - freeMemory));
    addValue("free", String.valueOf(freeMemory));
    endGroup();
    // END Memory status

    // BEGIN JRE
    startGroup("JRE");
    addValue("version", SystemUtils.JAVA_VERSION);
    atts.clear();
    // qName = prefix + ':' + localName
    atts.addAttribute(XLINK_NS, "type", XLINK_PREFIX + ":type", "CDATA", "simple");
    atts.addAttribute(XLINK_NS, "href", XLINK_PREFIX + ":href", "CDATA", SystemUtils.JAVA_VENDOR_URL);
    addValue("java-vendor", SystemUtils.JAVA_VENDOR, atts);
    endGroup();
    // END JRE

    // BEGIN Operating system
    startGroup("Operating System");
    addValue("name", SystemUtils.OS_NAME);
    addValue("architecture", SystemUtils.OS_ARCH);
    addValue("version", SystemUtils.OS_VERSION);
    endGroup();
    // END operating system

    // BEGIN Cache
    if (this.storeJanitor != null) {
        startGroup("Store Janitor");

        // For each element in StoreJanitor
        Iterator i = this.storeJanitor.iterator();
        while (i.hasNext()) {
            Store store = (Store) i.next();
            startGroup(
                    store.getClass().getName() + " (hash = 0x" + Integer.toHexString(store.hashCode()) + ")");
            int size = 0;
            int empty = 0;
            atts.clear();
            atts.addAttribute(NAMESPACE, "name", "name", "CDATA", "cached");
            super.contentHandler.startElement(NAMESPACE, "value", "value", atts);

            atts.clear();
            Enumeration e = store.keys();
            while (e.hasMoreElements()) {
                size++;
                Object key = e.nextElement();
                Object val = store.get(key);
                String line;
                if (val == null) {
                    empty++;
                } else {
                    line = key + " (class: " + val.getClass().getName() + ")";
                    super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                    super.contentHandler.characters(line.toCharArray(), 0, line.length());
                    super.contentHandler.endElement(NAMESPACE, "line", "line");
                }
            }
            if (size == 0) {
                super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                String value = "[empty]";
                super.contentHandler.characters(value.toCharArray(), 0, value.length());
                super.contentHandler.endElement(NAMESPACE, "line", "line");
            }
            super.contentHandler.endElement(NAMESPACE, "value", "value");

            addValue("size", String.valueOf(size) + " items in cache (" + empty + " are empty)");
            endGroup();
        }
        endGroup();
    }

    if (this.storePersistent != null) {
        startGroup(storePersistent.getClass().getName() + " (hash = 0x"
                + Integer.toHexString(storePersistent.hashCode()) + ")");
        int size = 0;
        int empty = 0;
        atts.clear();
        atts.addAttribute(NAMESPACE, "name", "name", "CDATA", "cached");
        super.contentHandler.startElement(NAMESPACE, "value", "value", atts);

        atts.clear();
        Enumeration e = this.storePersistent.keys();
        while (e.hasMoreElements()) {
            size++;
            Object key = e.nextElement();
            Object val = storePersistent.get(key);
            String line;
            if (val == null) {
                empty++;
            } else {
                line = key + " (class: " + val.getClass().getName() + ")";
                super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
                super.contentHandler.characters(line.toCharArray(), 0, line.length());
                super.contentHandler.endElement(NAMESPACE, "line", "line");
            }
        }
        if (size == 0) {
            super.contentHandler.startElement(NAMESPACE, "line", "line", atts);
            String value = "[empty]";
            super.contentHandler.characters(value.toCharArray(), 0, value.length());
            super.contentHandler.endElement(NAMESPACE, "line", "line");
        }
        super.contentHandler.endElement(NAMESPACE, "value", "value");

        addValue("size", size + " items in cache (" + empty + " are empty)");
        endGroup();
    }
    // END Cache

    endGroup();
}

From source file:org.apache.cocoon.portlet.CocoonPortlet.java

/**
 * Retreives the "extra-classpath" attribute, that needs to be
 * added to the class path.//  ww  w  .j  a  v a 2 s.  c  o  m
 *
 * @throws PortletException
 */
protected String getExtraClassPath() throws PortletException {
    String extraClassPath = this.getInitParameter("extra-classpath");
    if (extraClassPath != null) {
        StringBuffer sb = new StringBuffer();
        StringTokenizer st = new StringTokenizer(extraClassPath, SystemUtils.PATH_SEPARATOR, false);
        int i = 0;
        while (st.hasMoreTokens()) {
            String s = st.nextToken();
            if (i++ > 0) {
                sb.append(File.pathSeparatorChar);
            }
            if ((s.charAt(0) == File.separatorChar) || (s.charAt(1) == ':')) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("extraClassPath is absolute: " + s);
                }
                sb.append(s);

                addClassLoaderDirectory(s);
            } else {
                if (s.indexOf("${") != -1) {
                    String path = StringUtils.replaceToken(s);
                    sb.append(path);
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug(
                                "extraClassPath is not absolute replacing using token: [" + s + "] : " + path);
                    }
                    addClassLoaderDirectory(path);
                } else {
                    String path = null;
                    if (this.portletContextPath != null) {
                        path = this.portletContextPath + s;
                        if (getLogger().isDebugEnabled()) {
                            getLogger()
                                    .debug("extraClassPath is not absolute pre-pending context path: " + path);
                        }
                    } else {
                        path = this.workDir.toString() + s;
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug(
                                    "extraClassPath is not absolute pre-pending work-directory: " + path);
                        }
                    }
                    sb.append(path);
                    addClassLoaderDirectory(path);
                }
            }
        }
        return sb.toString();
    }
    return "";
}

From source file:org.apache.cocoon.servlet.CocoonServlet.java

/**
 * Retreives the "extra-classpath" attribute, that needs to be
 * added to the class path.// w w  w .  j  a  v  a2s .c  om
 *
 * @throws ServletException
 */
protected String getExtraClassPath() throws ServletException {
    String extraClassPath = this.getInitParameter("extra-classpath");
    if (extraClassPath != null) {
        StringBuffer sb = new StringBuffer();
        StringTokenizer st = new StringTokenizer(extraClassPath, SystemUtils.PATH_SEPARATOR, false);
        int i = 0;
        while (st.hasMoreTokens()) {
            String s = st.nextToken();
            if (i++ > 0) {
                sb.append(File.pathSeparatorChar);
            }
            if ((s.charAt(0) == File.separatorChar) || (s.charAt(1) == ':')) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("extraClassPath is absolute: " + s);
                }
                sb.append(s);

                addClassLoaderDirectory(s);
            } else {
                if (s.indexOf("${") != -1) {
                    String path = StringUtils.replaceToken(s);
                    sb.append(path);
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug(
                                "extraClassPath is not absolute replacing using token: [" + s + "] : " + path);
                    }
                    addClassLoaderDirectory(path);
                } else {
                    String path = null;
                    if (this.servletContextPath != null) {
                        path = this.servletContextPath + s;
                        if (getLogger().isDebugEnabled()) {
                            getLogger()
                                    .debug("extraClassPath is not absolute pre-pending context path: " + path);
                        }
                    } else {
                        path = this.workDir.toString() + s;
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug(
                                    "extraClassPath is not absolute pre-pending work-directory: " + path);
                        }
                    }
                    sb.append(path);
                    addClassLoaderDirectory(path);
                }
            }
        }
        return sb.toString();
    }
    return "";
}

From source file:org.apache.ctakes.jdl.common.FileUtil.java

/**
 * @return the javaClassPaths
 */
public static String[] getJavaClassPaths() {
    return SystemUtils.JAVA_CLASS_PATH.split(SystemUtils.PATH_SEPARATOR);
}

From source file:org.eclim.plugin.jdt.command.classpath.ClasspathCommand.java

/**
 * {@inheritDoc}//w  w w .  j  a  va 2  s . c  om
 * @see org.eclim.command.Command#execute(CommandLine)
 */
public Object execute(CommandLine commandLine) throws Exception {
    String name = commandLine.getValue(Options.PROJECT_OPTION);
    String delim = commandLine.getValue(Options.DELIMETER_OPTION, SystemUtils.PATH_SEPARATOR);
    IJavaProject javaProject = JavaUtils.getJavaProject(name);

    String[] paths = ClasspathUtils.getClasspath(javaProject);
    return StringUtils.join(paths, delim);
}