Example usage for java.io File pathSeparator

List of usage examples for java.io File pathSeparator

Introduction

In this page you can find the example usage for java.io File pathSeparator.

Prototype

String pathSeparator

To view the source code for java.io File pathSeparator.

Click Source Link

Document

The system-dependent path-separator character, represented as a string for convenience.

Usage

From source file:com.googlecode.jeeunit.jboss7.EmbeddedJBoss7Container.java

private URI buildWar() throws IOException {
    ScatteredArchive sar;/*from  w  w w.  ja  v  a2  s.c  o  m*/
    File webResourceDir = getWebResourceDir();
    if (webResourceDir.exists() && webResourceDir.isDirectory()) {
        sar = new ScatteredArchive("jeeunit-autodeploy", Type.WAR, webResourceDir);
    } else {
        sar = new ScatteredArchive("jeeunit-autodeploy", Type.WAR);
    }
    String classpath = System.getProperty("java.class.path");
    String[] pathElems = classpath.split(File.pathSeparator);

    for (String pathElem : pathElems) {
        File file = new File(pathElem);
        if (file.exists() && classpathFilter.accept(file)) {
            sar.addClassPath(file);
        }
    }
    for (File metadata : metadataFiles) {
        if (metadata.exists()) {
            sar.addMetadata(metadata);
        }
    }
    URI warUri = sar.toURI();
    File war = new File(warUri);
    jeeunitWar = new File(webappsDir, "jeeunit.war");
    FileUtils.copyFile(war, jeeunitWar);
    return warUri;
}

From source file:org.esa.s2tbx.dataio.gdal.GDALInstaller.java

private static boolean findFolderInPathEnvironment(Path folderPathToCheck, String pathEnvironment)
        throws IOException {
    String fullFolderPath = folderPathToCheck.toFile().getCanonicalPath();
    boolean foundFolderInPath = false;
    StringTokenizer str = new StringTokenizer(pathEnvironment, File.pathSeparator);
    while (str.hasMoreTokens() && !foundFolderInPath) {
        String currentFolderPathAsString = str.nextToken();
        Path currentFolderPath = Paths.get(currentFolderPathAsString);
        String currentFullFolderPath = currentFolderPath.toFile().getCanonicalPath();
        if (currentFullFolderPath.equals(fullFolderPath)) {
            foundFolderInPath = true;//from w  w  w.j a  va 2s. c om
        }
    }
    return foundFolderInPath;
}

From source file:org.apache.hadoop.hdfs.server.namenode.NNStorageDirectoryRetentionManager.java

/**
 * List all directories that match the backup pattern.
 * Sort from oldest to newest.//from w  w w . j av a2s  .c  om
 */
static String[] getBackups(File origin) {
    File root = origin.getParentFile();
    final String originName = origin.getName();

    String[] backups = root.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            if (!name.startsWith(originName + File.pathSeparator) || name.equals(originName))
                return false;
            try {
                dateForm.get().parse(name.substring(name.indexOf(File.pathSeparator) + 1));
            } catch (ParseException pex) {
                return false;
            }
            return true;
        }
    });
    if (backups == null)
        return new String[0];

    Arrays.sort(backups, new Comparator<String>() {

        @Override
        public int compare(String back1, String back2) {
            try {
                Date date1 = dateForm.get().parse(back1.substring(back1.indexOf(File.pathSeparator) + 1));
                Date date2 = dateForm.get().parse(back2.substring(back2.indexOf(File.pathSeparator) + 1));
                // Sorting in reverse order, from later dates to earlier
                return -1 * date2.compareTo(date1);
            } catch (ParseException pex) {
                return 0;
            }
        }
    });
    return backups;
}

From source file:org.apache.sysml.runtime.codegen.CodegenUtils.java

private static Class<?> compileClassJavac(String name, String src) {
    try {//from w w  w  .j a v  a  2  s.  c om
        //create working dir on demand
        if (_workingDir == null)
            createWorkingDir();

        //write input file (for debugging / classpath handling)
        File ftmp = new File(_workingDir + "/" + name.replace(".", "/") + ".java");
        if (!ftmp.getParentFile().exists())
            ftmp.getParentFile().mkdirs();
        LocalFileUtils.writeTextFile(ftmp, src);

        //get system java compiler
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        if (compiler == null)
            throw new RuntimeException("Unable to obtain system java compiler.");

        //prepare file manager
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);

        //prepare input source code
        Iterable<? extends JavaFileObject> sources = fileManager
                .getJavaFileObjectsFromFiles(Arrays.asList(ftmp));

        //prepare class path 
        URL runDir = CodegenUtils.class.getProtectionDomain().getCodeSource().getLocation();
        String classpath = System.getProperty("java.class.path") + File.pathSeparator + runDir.getPath();
        List<String> options = Arrays.asList("-classpath", classpath);

        //compile source code
        CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, sources);
        Boolean success = task.call();

        //output diagnostics and error handling
        for (Diagnostic<? extends JavaFileObject> tmp : diagnostics.getDiagnostics())
            if (tmp.getKind() == Kind.ERROR)
                System.err.println("ERROR: " + tmp.toString());
        if (success == null || !success)
            throw new RuntimeException("Failed to compile class " + name);

        //dynamically load compiled class
        URLClassLoader classLoader = null;
        try {
            classLoader = new URLClassLoader(new URL[] { new File(_workingDir).toURI().toURL(), runDir },
                    CodegenUtils.class.getClassLoader());
            return classLoader.loadClass(name);
        } finally {
            IOUtilFunctions.closeSilently(classLoader);
        }
    } catch (Exception ex) {
        LOG.error("Failed to compile class " + name + ": \n" + src);
        throw new DMLRuntimeException("Failed to compile class " + name + ".", ex);
    }
}

From source file:net.grinder.util.AbstractGrinderClassPathProcessor.java

/**
 * Construct the foremost classPath from current classLoader.
 *
 * @param logger logger//from  ww  w. j a  v a  2  s.  c  o m
 * @return classpath optimized for grinder.
 */
public String buildForemostClasspathBasedOnCurrentClassLoader(Logger logger) {
    URL[] urLs = ((URLClassLoader) AbstractGrinderClassPathProcessor.class.getClassLoader()).getURLs();
    StringBuilder builder = new StringBuilder();
    for (URL each : urLs) {
        builder.append(each.getFile()).append(File.pathSeparator);
    }
    return filterForeMostClassPath(builder.toString(), logger);
}

From source file:com.twosigma.beakerx.kernel.magic.command.MavenJarResolver.java

private List<String> mavenBuildClasspath() {
    String jarPathsAsString = null;
    try {// w  w w  . j  a  v  a  2  s.  com
        File fileToClasspath = new File(pathToMavenRepo, MAVEN_BUILT_CLASSPATH_FILE_NAME);
        InputStream fileInputStream = new FileInputStream(fileToClasspath);
        jarPathsAsString = IOUtils.toString(fileInputStream, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Stream<String> stream = Arrays.stream(jarPathsAsString.split(File.pathSeparator));
    return stream.map(x -> Paths.get(x).getFileName().toString()).collect(Collectors.toList());
}

From source file:org.apache.carbondata.processing.newflow.DataLoadProcessBuilder.java

public static CarbonDataLoadConfiguration createConfiguration(CarbonLoadModel loadModel,
        String[] storeLocation) {
    CarbonDataProcessorUtil.createLocations(storeLocation);

    String databaseName = loadModel.getDatabaseName();
    String tableName = loadModel.getTableName();
    String tempLocationKey = CarbonDataProcessorUtil.getTempStoreLocationKey(databaseName, tableName,
            loadModel.getSegmentId(), loadModel.getTaskNo(), false);
    CarbonProperties.getInstance().addProperty(tempLocationKey,
            StringUtils.join(storeLocation, File.pathSeparator));
    CarbonProperties.getInstance().addProperty(CarbonCommonConstants.STORE_LOCATION_HDFS,
            loadModel.getStorePath());//from  w ww.  java 2s. c o  m

    return createConfiguration(loadModel);
}

From source file:io.hops.hopsworks.common.util.HopsUtils.java

/**
 * Retrieves the global hadoop classpath.
 *
 * @param params/*  w w  w. j  a v  a  2  s . c o  m*/
 * @return hadoop global classpath
 */
public static String getHadoopClasspathGlob(String... params) {
    ProcessBuilder pb = new ProcessBuilder(params);
    try {
        Process process = pb.start();
        int errCode = process.waitFor();
        if (errCode != 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        }
        //Now we must remove the yarn shuffle library as it creates issues for 
        //Zeppelin Spark Interpreter
        StringBuilder classpath = new StringBuilder();

        for (String path : sb.toString().split(File.pathSeparator)) {
            if (!path.contains("yarn") && !path.contains("jersey") && !path.contains("servlet")) {
                classpath.append(path).append(File.pathSeparator);
            }
        }
        if (classpath.length() > 0) {
            return classpath.toString().substring(0, classpath.length() - 1);
        }

    } catch (IOException | InterruptedException ex) {
        Logger.getLogger(HopsUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
    return "";
}

From source file:edu.rice.dca.soaplabPBS.PBSJob.java

/**************************************************************************
 * Update the environment variable PATH by our own directories
 * 'dirs' (taken originally from the Soaplab's property {@link
 * Config#PROP_ADDTOPATH_DIR})./*from  w w w  .  j a va  2 s  .  c om*/
 *
 * Note that updating the PATH variable does not have any effect
 * on finding the executable - but it is made available to the
 * executable once the executable has been started (which solves,
 * for example, EMBOSS's wossname problem).
 *
 * The updated variable is stored in the given 'env'.
 **************************************************************************/
protected void addToPath(Map<String, String> env, String[] dirs) {
    if (dirs == null || dirs.length == 0)
        return;
    String path = System.getenv("PATH");
    if (path == null)
        return;

    StringBuilder buf = new StringBuilder();
    for (String dir : dirs) {
        buf.append(dir);
        buf.append(File.pathSeparator);
    }
    buf.append(path);
    env.put("PATH", buf.toString());
}

From source file:com.qwazr.server.configuration.ServerConfiguration.java

private static Set<Path> getEtcDirectories(final String value) {
    final Set<Path> set = new LinkedHashSet<>();
    fillStringListProperty(value == null ? "etc" : value, File.pathSeparator, true, part -> {
        // By design relative path are relative to the working directory
        final Path etcPath = Paths.get(part);
        set.add(etcPath);/*from   w w  w .  j  a  va 2 s .c om*/
        LOGGER.info("Configuration (ETC) directory: " + etcPath.toAbsolutePath());
    });
    return Collections.unmodifiableSet(set);
}