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:dk.netarkivet.common.utils.SystemUtils.java

/** Get the current class path entries.  Note that this does not work
 * if we've been invoked with java -jar, as that option silently ignores
 * classpaths.//from  w w  w.j  ava2 s .co m
 *
 * @return List of directories/jar files in the current class path.
 */
public static List<String> getCurrentClasspath() {
    String propertyValue = System.getProperty(CLASS_PATH_PROPERTY);
    if (propertyValue != null) {
        final String[] pathArray = propertyValue.split(File.pathSeparator);
        return new ArrayList<String>(Arrays.asList(pathArray));
    } else {
        return new ArrayList<String>();
    }
}

From source file:dk.netarkivet.common.utils.Settings.java

/**
 * Return the file these settings are read from. If the property given in
 * the constructor is set, that will be used to determine the file. If it is
 * not set, the default settings file path given in the constructor will be
 * used.// w w w . j  a  v  a 2s  .  c  om
 *
 * @return The settings file.
 */
public static List<File> getSettingsFiles() {
    String[] pathList = System.getProperty(SETTINGS_FILE_PROPERTY, DEFAULT_SETTINGS_FILEPATH)
            .split(File.pathSeparator);
    List<File> result = new ArrayList<File>();
    for (String path : pathList) {
        if (path.trim().length() != 0) {
            File settingsFile = new File(path);
            if (settingsFile.isFile()) {
                result.add(settingsFile);
            }
        }
    }
    return result;
}

From source file:eu.stratosphere.nephele.io.channels.FileBufferManager.java

/**
 * Constructs a new file buffer manager object.
 *//*from  w w  w . j  ava  2 s  .co  m*/
private FileBufferManager() {

    this.tmpDirs = GlobalConfiguration
            .getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH)
            .split(File.pathSeparator);

    // check temp dirs
    for (int i = 0; i < this.tmpDirs.length; i++) {
        File f = new File(this.tmpDirs[i]);
        if (!(f.exists() && f.isDirectory() && f.canWrite())) {
            LOG.error("Temp directory '" + f.getAbsolutePath() + "' is not a writable directory. "
                    + "Replacing path with default temp directory: "
                    + ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH);
            this.tmpDirs[i] = ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH;
        }
        this.tmpDirs[i] = this.tmpDirs[i] + File.separator + FILE_BUFFER_PREFIX;
    }

    this.bufferSize = GlobalConfiguration.getInteger("channel.network.bufferSizeInBytes", 64 * 1024); // TODO: Use
    // config
    // constants
    // here

    this.fileMap = new ConcurrentHashMap<AbstractID, ChannelWithAccessInfo>(2048, 0.8f, 64);

    this.distributedTempPath = CheckpointUtils.getDistributedCheckpointPath();
    FileSystem distFS = null;
    if (this.distributedTempPath != null && CheckpointUtils.allowDistributedCheckpoints()) {

        try {

            distFS = this.distributedTempPath.getFileSystem();
            if (!distFS.exists(this.distributedTempPath)) {
                distFS.mkdirs(this.distributedTempPath);
            }

        } catch (IOException e) {
            LOG.error(StringUtils.stringifyException(e));
        }
    }

    this.distributedFileSystem = distFS;
}

From source file:com.nike.cerberus.operation.gateway.PublishLambdaOperation.java

private File downloadArtifact(final URL artifactUrl) {
    final File tempDir = Files.createTempDir();
    final String filePath = tempDir.getPath() + File.pathSeparator + "lambda.artifact";
    logger.debug("Downloading artifact to {}", tempDir.getAbsolutePath());

    try {/*from ww  w. ja v a  2 s.c  o  m*/
        ReadableByteChannel rbc = Channels.newChannel(artifactUrl.openStream());
        FileOutputStream fos = new FileOutputStream(filePath);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    } catch (IOException e) {
        logger.error("Failed to download the lambda artifact!", e);
        throw new IllegalStateException("Failed to download the lambda artifact.", e);
    }

    return new File(filePath);
}

From source file:com.netflix.priam.backup.AbstractRestore.java

protected void download(Iterator<AbstractBackupPath> fsIterator, BackupFileType filter) throws Exception {
    while (fsIterator.hasNext()) {
        AbstractBackupPath temp = fsIterator.next();
        if (temp.type == BackupFileType.SST && tracker.contains(temp))
            continue;

        if (temp.getType() == filter) {
            File localFileHandler = temp.newRestoreFile();
            logger.debug("Created local file name: " + localFileHandler.getAbsolutePath() + File.pathSeparator
                    + localFileHandler.getName());
            download(temp, localFileHandler);
        }//from w  ww  . ja v  a  2 s . c  o m
    }
    waitToComplete();
}

From source file:org.lantern.CommandLine.java

/**
 * Find the executable by scanning the file system and the PATH. In the case
 * of Windows this method allows common executable endings (".com", ".bat" and
 * ".exe") to be omitted.//from w ww. j  ava2  s  . c  om
 *
 * @param named The name of the executable to find
 * @return The absolute path to the executable, or null if no match is made.
 */
public static String findExecutable(String named) {
    File file = new File(named);
    if (canExecute(file)) {
        return named;
    }

    Map<String, String> env = System.getenv();
    String pathName = "PATH";
    if (!env.containsKey("PATH")) {
        for (String key : env.keySet()) {
            if ("path".equalsIgnoreCase(key)) {
                pathName = key;
                break;
            }
        }
    }

    String path = env.get(pathName);
    String[] endings = new String[] { "" };
    if (SystemUtils.IS_OS_WINDOWS) {
        endings = new String[] { "", ".exe", ".com", ".bat" };
    }

    for (String segment : path.split(File.pathSeparator)) {
        for (String ending : endings) {
            file = new File(segment, named + ending);
            if (canExecute(file)) {
                return file.getAbsolutePath();
            }
        }
    }

    return null;
}

From source file:gov.nih.nci.restgen.util.GeneratorUtil.java

public static boolean compileJavaSource(String srcFolder, String destFolder, String libFolder,
        GeneratorContext context) {//from   www .  j  a  va2s  .  co m
    StandardJavaFileManager fileManager = null;
    boolean success = true;
    try {
        List<String> compilerFiles = GeneratorUtil.getFiles(srcFolder, new String[] { "java" });

        GeneratorUtil.createOutputDir(destFolder);

        List<String> options = new ArrayList<String>();
        options.add("-classpath");
        String classPathStr = GeneratorUtil.getFiles(libFolder, new String[] { "jar" }, File.pathSeparator);

        options.add(classPathStr);
        options.add("-nowarn");
        options.add("-Xlint:-unchecked");
        options.add("-d");
        options.add(destFolder);

        options.add("-s");
        options.add(srcFolder);

        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
        fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        Iterable<? extends JavaFileObject> compilationUnits = fileManager
                .getJavaFileObjectsFromStrings(compilerFiles);
        JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null,
                compilationUnits);
        success = task.call();

        for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
            //context.getLogger().error(diagnostic.getCode());
            //context.getLogger().error(diagnostic.getKind().toString());
            //context.getLogger().error(diagnostic.getPosition() + "");
            //context.getLogger().error(diagnostic.getStartPosition() + "");
            //context.getLogger().error(diagnostic.getEndPosition() + "");
            //context.getLogger().error(diagnostic.getSource().toString());
            context.getLogger().error(diagnostic.toString());
        }
    } catch (Throwable t) {
        context.getLogger().error("Error compiling java code", t);
    } finally {
        try {
            fileManager.close();
        } catch (Throwable t) {
        }
    }
    return success;
}

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

@Test
public void testSortedListBackups() throws Exception {
    conf.setInt(StandbyStorageRetentionManager.STANDBY_IMAGE_DAYS_TOKEEP, 0);
    conf.setInt(StandbyStorageRetentionManager.STANDBY_IMAGE_COPIES_TOKEEP, 0);

    String[] backups = createBackups(10, conf, dir, fs, -1);
    assertEquals(10, backups.length);/*from   w  w  w .  ja  v  a2  s .c om*/
    Date[] backupDates = new Date[backups.length];
    for (int i = 0; i < backups.length; i++) {
        String b = backups[i];
        backupDates[i] = StandbyStorageRetentionManager.dateForm
                .parse(b.substring(b.indexOf(File.pathSeparator) + 1));
    }

    // aseert that the copies are sorted from oldest to newest
    for (int i = 1; i < backupDates.length; i++) {
        backupDates[i].after(backupDates[i - 1]);
    }
}

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

@Test
public void testSortedListBackups() throws Exception {
    conf.setInt(NNStorageDirectoryRetentionManager.NN_IMAGE_DAYS_TOKEEP, 0);
    conf.setInt(NNStorageDirectoryRetentionManager.NN_IMAGE_COPIES_TOKEEP, 0);

    String[] backups = createBackups(10, conf, dir, fs, -1);
    assertEquals(10, backups.length);/*from   ww  w .j a va2  s .  c o m*/
    Date[] backupDates = new Date[backups.length];
    for (int i = 0; i < backups.length; i++) {
        String b = backups[i];
        backupDates[i] = NNStorageDirectoryRetentionManager.dateForm.get()
                .parse(b.substring(b.indexOf(File.pathSeparator) + 1));
    }

    // aseert that the copies are sorted from oldest to newest
    for (int i = 1; i < backupDates.length; i++) {
        backupDates[i].after(backupDates[i - 1]);
    }
}

From source file:ch.ivyteam.ivy.maven.engine.EngineControl.java

private CommandLine toEngineCommand(Command command) {
    String classpath = context.engineClasspathJarPath;
    if (StringUtils.isNotBlank(context.vmOptions.additionalClasspath)) {
        classpath += File.pathSeparator + context.vmOptions.additionalClasspath;
    }/*from w w w  .j a  v  a2 s . c  om*/

    CommandLine cli = new CommandLine(new File(getJavaExec())).addArgument("-classpath").addArgument(classpath)
            .addArgument("-Dosgi.install.area=" + context.engineDirectory);
    if (StringUtils.isNotBlank(context.vmOptions.additionalVmOptions)) {
        cli.addArgument(context.vmOptions.additionalVmOptions, false);
    }
    cli.addArgument("org.eclipse.equinox.launcher.Main").addArgument("-application")
            .addArgument("ch.ivyteam.ivy.server.exec.engine").addArgument(command.toString());
    return cli;
}