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.chinalbs.service.impl.FileServiceImpl.java

private void proccessImage(File tempFile, String sourcePath, String resizedPath, Integer width, Integer height,
        boolean moveSource) {
    String tempPath = System.getProperty("java.io.tmpdir");
    File resizedFile = new File(
            tempPath + File.pathSeparator + "upload_" + UUID.randomUUID() + "." + DEST_EXTENSION);
    ImageUtils.zoom(tempFile, resizedFile, width, height);

    File destFile = new File(resizedPath);
    try {/*from   w  w w .j a v a2s  .c  o  m*/
        if (moveSource) {
            File destSrcFile = new File(sourcePath);
            FileUtils.moveFile(tempFile, destSrcFile);
        }
        FileUtils.moveFile(resizedFile, destFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.hadoop.util.TestApplicationClassLoader.java

@Test
public void testConstructUrlsFromClasspath() throws Exception {
    File file = new File(testDir, "file");
    assertTrue("Create file", file.createNewFile());

    File dir = new File(testDir, "dir");
    assertTrue("Make dir", dir.mkdir());

    File jarsDir = new File(testDir, "jarsdir");
    assertTrue("Make jarsDir", jarsDir.mkdir());
    File nonJarFile = new File(jarsDir, "nonjar");
    assertTrue("Create non-jar file", nonJarFile.createNewFile());
    File jarFile = new File(jarsDir, "a.jar");
    assertTrue("Create jar file", jarFile.createNewFile());

    File nofile = new File(testDir, "nofile");
    // don't create nofile

    StringBuilder cp = new StringBuilder();
    cp.append(file.getAbsolutePath()).append(File.pathSeparator).append(dir.getAbsolutePath())
            .append(File.pathSeparator).append(jarsDir.getAbsolutePath() + "/*").append(File.pathSeparator)
            .append(nofile.getAbsolutePath()).append(File.pathSeparator).append(nofile.getAbsolutePath() + "/*")
            .append(File.pathSeparator);

    URL[] urls = constructUrlsFromClasspath(cp.toString());

    assertEquals(3, urls.length);/*ww  w  . j a v  a2s  .c o m*/
    assertEquals(file.toURI().toURL(), urls[0]);
    assertEquals(dir.toURI().toURL(), urls[1]);
    assertEquals(jarFile.toURI().toURL(), urls[2]);
    // nofile should be ignored
}

From source file:de.codesourcery.jasm16.compiler.io.FileResourceResolver.java

private boolean isAbsolutePath(String path) {
    return path.startsWith(File.pathSeparator);
}

From source file:gool.executor.java.JavaCompiler.java

private void addClasspathArgs(List<File> classPath, List<String> params) {
    /*//from w  w  w  .j a  v  a2  s . c o  m
     * Add the classpath
     */
    params.add("-classpath");
    String cp = ".";
    if (classPath != null && !classPath.isEmpty()) {
        cp += File.pathSeparator + StringUtils.join(classPath, File.pathSeparator);
    }
    if (!getDependencies().isEmpty()) {
        cp += File.pathSeparator + StringUtils.join(getDependencies(), File.pathSeparator);
    }
    params.add(cp);
}

From source file:com.jstar.eclipse.services.JStar.java

@SuppressWarnings("static-access")
// in io 2.0 FileUtils.listFiles should return Collection<File> instead of Collection
public List<File> convertToJimple(final JavaFile fileToConvert) {
    String fileDirectory = fileToConvert.getOutputDirectory().getLocation().toOSString();
    String javaFile = fileToConvert.getNameWithPackage();

    final String sootOutput = fileDirectory + File.separator + SootOutput + File.separator + javaFile;

    final String[] args = { "-cp",
            PreferenceConstants.getSootClassPath() + File.pathSeparator + fileToConvert.getProjectClasspath(),
            "-f", "J", "-output-dir", sootOutput, "-src-prec", "java",
            //"-v",
            "-print-tags", javaFile };

    soot.G.v().reset();//from  w  ww.ja  va  2s . c  o m
    soot.Main.main(args);

    final List<String> types = fileToConvert.getTypes();
    final List<File> jimpleFiles = new LinkedList<File>();

    for (Object file : (FileUtils.listFiles(new File(sootOutput), new WildcardFileFilter("*.jimple"), null))) {
        final String fileName = ((File) file).getName();

        if (types.indexOf(new Path(fileName).removeFileExtension().toOSString()) != -1) {
            jimpleFiles.add((File) file);
        }
    }

    if (jimpleFiles == null || jimpleFiles.size() == 0) {
        ConsoleService.getInstance()
                .printErrorMessage("An error occurred while converting java file to jimple format.");
        throw new NullPointerException();
    }

    return jimpleFiles;
}

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

/**
 * Backup given directory./*from  www  .  ja v a2s . c o  m*/
 * Enforce that max number of backups has not been reached.
 */
public static void backupFiles(FileSystem fs, File dest, Configuration conf) throws IOException {
    // check if we can still backup
    cleanUpAndCheckBackup(conf, dest);

    int MAX_ATTEMPT = 3;
    for (int i = 0; i < MAX_ATTEMPT; i++) {
        try {
            String mdate = dateForm.get().format(new Date(System.currentTimeMillis()));
            if (dest.exists()) {
                File tmp = new File(dest + File.pathSeparator + mdate);
                FLOG.info("Moving aside " + dest + " as " + tmp);
                if (!dest.renameTo(tmp)) {
                    throw new IOException("Unable to rename " + dest + " to " + tmp);
                }
                FLOG.info("Moved aside " + dest + " as " + tmp);
            }
            return;
        } catch (IOException e) {
            FLOG.error("Creating backup exception. Will retry ", e);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException iex) {
                throw new IOException(iex);
            }
        }
    }
    throw new IOException("Cannot create backup for: " + dest);
}

From source file:org.grycap.gpf4med.graph.base.visual.GraphvizPrinter.java

public static File print3(final GraphDatabaseService graphDb, final String filename) throws IOException {
    checkArgument(graphDb != null, "Uninitialized database");
    checkArgument(StringUtils.isNotBlank(filename), "Uninitialized or invalid filename");
    final File file = new File(ConfigurationManager.INSTANCE.getLocalCacheDir(),
            CACHE_DIRNAME + File.pathSeparator + filename);
    try (final Transaction tx = graphDb.beginTx()) {
        final GraphvizWriter writer = new GraphvizWriter(AsciiDocSimpleStyle.withoutColors());
        writer.emit(file, Walker.fullGraph(graphDb));
        tx.success();//from   w ww .j  av a2s .co m
    }
    return file;
}

From source file:com.withinet.opaas.controller.system.impl.PaxJavaRunner.java

/**
 * {@inheritDoc}//from www.  ja  v a 2 s. c  o  m
 * @return
 */
public void exec(final String[] vmOptions, final String[] classpath, final String mainClass,
        final String[] programOptions, final String javaHome, final File workingDirectory,
        final String[] envOptions) throws PlatformException {
    if (m_frameworkProcess != null) {
        throw new PlatformException("Platform already started");
    }

    final StringBuilder cp = new StringBuilder();

    for (String path : classpath) {
        if (cp.length() != 0) {
            cp.append(File.pathSeparator);
        }
        cp.append(path);
    }

    final CommandLineBuilder commandLine = new CommandLineBuilder().append(getJavaExecutable(javaHome))
            .append(vmOptions).append("-cp").append(cp.toString()).append(mainClass).append(programOptions);

    LOG.debug("Start command line [" + Arrays.toString(commandLine.toArray()) + "]");

    try {
        LOG.debug("Starting platform process.");
        m_frameworkProcess = Runtime.getRuntime().exec(commandLine.toArray(), createEnvironmentVars(envOptions),
                workingDirectory);
    } catch (IOException e) {
        throw new PlatformException("Could not start up the process", e);
    }

    LOG.info("Runner has successfully finished his job!");
    if (m_wait == true) {
        try {
            this.m_frameworkProcess.waitFor();
        } catch (InterruptedException e) {
            LOG.debug(e.toString());
        }
    }
}

From source file:com.twosigma.beaker.sql.JDBCClient.java

public void loadDrivers(List<String> pathList) {
    synchronized (this) {

        dsMap = new HashMap<>();
        drivers = new HashSet<>();

        Set<URL> urlSet = new HashSet<>();

        String dbDriverString = System.getenv("BEAKER_JDBC_DRIVER_LIST");
        if (dbDriverString != null && !dbDriverString.isEmpty()) {
            String[] dbDriverList = dbDriverString.split(File.pathSeparator);
            for (String s : dbDriverList) {
                try {
                    urlSet.add(toURL(s));
                } catch (MalformedURLException e) {
                    logger.error(e.getMessage());
                }//from w w w  .j av  a  2 s .com
            }
        }

        if (pathList != null) {
            for (String path : pathList) {
                path = path.trim();
                if (path.startsWith("--") || path.startsWith("#")) {
                    continue;
                }
                try {
                    urlSet.add(toURL(path));
                } catch (MalformedURLException e) {
                    logger.error(e.getMessage());
                }
            }
        }

        URLClassLoader loader = new URLClassLoader(urlSet.toArray(new URL[urlSet.size()]));

        ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class, loader);
        Iterator<Driver> driversIterator = loadedDrivers.iterator();
        try {
            while (driversIterator.hasNext()) {
                Driver d = driversIterator.next();
                drivers.add(d);
            }
        } catch (Throwable t) {
            logger.error(t.getMessage());
        }
    }
}

From source file:org.codehaus.mojo.webtest.components.AntExecutor.java

/**
 * Run an ANT script within the JVM../* w  w w .  j av a2 s  . c  om*/
 *
 * @param antFile        the ANT scripts to be executed
 * @param userProperties the properties to be set for the ANT script
 * @param mavenProject   the current maven project
 * @param artifacts      the list of dependencies
 * @param target         the ANT target to be executed
 * @throws DependencyResolutionRequiredException
 *                        not dependencies were resolved
 * @throws BuildException the build failed
 */
public AntExecutor(File antFile, Properties userProperties, MavenProject mavenProject, List artifacts,
        String target) throws BuildException, DependencyResolutionRequiredException {
    File antBaseDir = antFile.getParentFile();

    Project antProject = new Project();

    antProject.init();
    antProject.addBuildListener(this.createLogger());
    antProject.setBaseDir(antBaseDir);

    ProjectHelper2.configureProject(antProject, antFile);
    // ProjectHelper2 projectHelper = new ProjectHelper2();
    // projectHelper.parse( antProject, antFile );

    Enumeration propertyKeys = userProperties.keys();
    while (propertyKeys.hasMoreElements()) {
        String key = (String) propertyKeys.nextElement();
        String value = userProperties.getProperty(key);
        antProject.setUserProperty(key, value);
    }

    // NOTE: from maven-antrun-plugin

    Path p = new Path(antProject);
    p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator));

    /* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */
    antProject.addReference("maven.dependency.classpath", p);
    antProject.addReference("maven.compile.classpath", p);

    p = new Path(antProject);
    p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator));
    antProject.addReference("maven.runtime.classpath", p);

    p = new Path(antProject);
    p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator));
    antProject.addReference("maven.test.classpath", p);

    /* set maven.plugin.classpath with plugin dependencies */
    antProject.addReference("maven.plugin.classpath", getPathFromArtifacts(artifacts, antProject));

    antProject.executeTarget(target);
}