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:net.ion.radon.impl.let.webdav.VFSResource.java

/**
 * On Windows platform, work around excessive locking of files in read
 * mode by using string parses where size allows for it and the type is
 * known to be textual./*from   www. ja  v a 2s  . c o  m*/
 */
public static Representation getRepresentationForFile(VFS vfs, VFSPath uri) throws NotFoundException {
    Representation r = null;
    String s = uri.toString();
    if ("\\".equals(File.pathSeparator) && (s.endsWith(".xml") || s.endsWith(".html") || s.endsWith(".txt"))) {
        try {
            r = new StringRepresentation(vfs.getString(uri), MediaTypeManager.getMediaType(s));
        } catch (IOException io) {
            r = null;
        }
    }
    if (r == null) {
        r = new InputRepresentation(vfs.getInputStream(uri), MediaTypeManager.getMediaType(s));
    }
    r.setSize(vfs.getLength(uri));
    r.setModificationDate(new Date(vfs.getLastModified(uri)));
    r.setTag(new Tag(vfs.getETag(uri)));
    return r;
}

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

/**
 * List all directories that match the backup pattern.
 * Sort from oldest to newest.// w w w  . j  a v  a 2  s. co  m
 */
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.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.parse(back1.substring(back1.indexOf(File.pathSeparator) + 1));
                Date date2 = dateForm.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:com.googlecode.jeeunit.resin.EmbeddedResinContainer.java

private File buildWar() throws IOException {
    ScatteredArchive sar;/*from  ww w. j  av  a  2 s . c om*/
    File webResourceDir = new File("src/main/webapp");
    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);
    File warFile = new File(tempDir, "jeeunit.war");
    copyFile(war, warFile);
    return war;
}

From source file:fr.inria.eventcloud.deployment.cli.launchers.EventCloudsManagementServiceDeployer.java

private static String addClassPath(String libsUrl) throws IOException {
    downloadLibs(libsUrl);//from ww w  .  j a  v a 2  s  . c  om

    File libDir = new File(libDirPath);
    String[] libNames = libDir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });

    StringBuilder classPath = new StringBuilder();
    for (String libName : libNames) {
        classPath.append(libDirPath).append(File.separator).append(libName).append(File.pathSeparator);
    }
    classPath.delete(classPath.length() - 2, classPath.length() - 1);

    return classPath.toString();
}

From source file:net.larry1123.elec.util.logger.LoggerDirectoryHandler.java

/**
 * Makes a formatted String//from w  w w .j ava2  s.  c  om
 *
 * @param milli What milli time to use
 *
 * @return The formatted String
 */
public String getDateFormatFromMilli(long milli) {
    return DateFormatUtils.ISO_DATETIME_FORMAT.format(milli).replace(":", File.pathSeparator);
}

From source file:es.mityc.firmaJava.libreria.utilidades.CopiaFicherosManager.java

/**
 * Actualiza la variable java.library.path con la nueva ruta indicada.
 * /*from  w  w w  .j a v  a  2  s  . co m*/
 * <br/><br/>Esta variable permite indicar dnde se encuentran las libreras JNI de usuario que se van a utilizar.
 *  
 * @param path Nueva ruta a incluir
 */
public void updateLibraryPath(String path) {
    String libPath = System.getProperty("java.library.path");
    File fileDir = new File(path);
    if (!libPath.contains(fileDir.getAbsolutePath())) {
        libPath = fileDir.getAbsolutePath() + File.pathSeparator + libPath;
        System.setProperty("java.library.path", libPath);
        try {
            Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
            fieldSysPath.setAccessible(true);
            if (fieldSysPath != null)
                fieldSysPath.set(System.class.getClassLoader(), null);
        } catch (NoSuchFieldException ex) {
            log.error("Error estableciendo path", ex);
        } catch (IllegalAccessException ex) {
            log.error("Error estableciendo path", ex);
        }
    }
}

From source file:jenkins.model.RunIdMigrator.java

private static String getUnmigrationCommandLine(File jenkinsHome) {
    StringBuilder cp = new StringBuilder();
    for (Class<?> c : new Class<?>[] { RunIdMigrator.class,
            /* TODO how to calculate transitive dependencies automatically? */Charsets.class,
            WriterOutputStream.class, BuildException.class, FastDateFormat.class }) {
        URL location = c.getProtectionDomain().getCodeSource().getLocation();
        String locationS = location.toString();
        if (location.getProtocol().equals("file")) {
            try {
                locationS = new File(location.toURI()).getAbsolutePath();
            } catch (URISyntaxException x) {
                // never mind
            }//from   w w  w.j av  a2s .c  o m
        }
        if (cp.length() > 0) {
            cp.append(File.pathSeparator);
        }
        cp.append(locationS);
    }
    return String.format("java -classpath \"%s\" %s \"%s\"", cp, RunIdMigrator.class.getName(), jenkinsHome);
}

From source file:io.fabric8.vertx.maven.plugin.mojos.AbstractRunMojo.java

/**
 * This add or build the classpath that will be passed to the forked process JVM i.e &quot;-cp&quot;
 *
 * @param args - the forked process argument list to which the classpath will be appended
 * @throws MojoExecutionException - any error that might occur while building or adding classpath
 *//*from  ww  w  . ja  va  2 s .  c  om*/
protected void addClasspath(List<String> args) throws MojoExecutionException {
    try {
        StringBuilder classpath = new StringBuilder();
        for (URL ele : getClassPathUrls()) {
            classpath = classpath.append(classpath.length() > 0 ? File.pathSeparator : "")
                    .append(new File(ele.toURI()));
        }
        getLog().debug("Classpath for forked process: " + classpath);
        args.add("-cp");
        args.add(classpath.toString());
    } catch (Exception ex) {
        throw new MojoExecutionException("Could not build classpath", ex);
    }
}

From source file:org.evosuite.junit.CoverageAnalysisOfProjectSystemTest.java

@Test
public void testMoreThanOneClassMoreThanOneCriterion() throws IOException {
    createFakeProject();/*  w w  w.ja v a 2  s . c  om*/

    EvoSuite evosuite = new EvoSuite();

    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH,
            Properties.Criterion.LINE };
    Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;

    String[] command = new String[] { "-target", this.classes_directory.getAbsolutePath(),
            "-Djunit=" + this.tests_directory.getAbsolutePath(), "-projectCP",
            this.classes_directory.getAbsolutePath() + File.pathSeparator
                    + this.tests_directory.getAbsolutePath(),
            "-measureCoverage" };

    SearchStatistics statistics = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(statistics);

    String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR
            + File.separator + "statistics.csv";

    CSVReader reader = new CSVReader(new FileReader(statistics_file));
    List<String[]> rows = reader.readAll();
    assertTrue(rows.size() == 8); // header + 7 classes
    reader.close();

    // assert TargetClasses
    List<String> classes = CsvJUnitData.getValues(rows, "TARGET_CLASS");
    assertTrue(classes.contains(Calculator.class.getCanonicalName()));
    assertTrue(classes.contains(MethodWithSeveralInputArguments.class.getCanonicalName()));
    assertTrue(classes.contains(WordUtils.class.getCanonicalName()));
    assertTrue(classes.contains(FinalClass.class.getCanonicalName()));
    assertTrue(classes.contains(StringUtils.class.getCanonicalName()));
    assertTrue(classes.contains(ClassNumberUtils.class.getCanonicalName()));
    assertTrue(classes.contains(ClassWithPrivateInterfaces.class.getCanonicalName()));

    // assert Coverage
    List<String> coverages = CsvJUnitData.getValues(rows, "Coverage");
    assertTrue(coverages.size() == 7);
    Collections.sort(coverages);
    //        assertEquals(0.45, Double.valueOf(coverages.get(0)), 0.01);
    //        assertEquals(0.47, Double.valueOf(coverages.get(1)), 0.01);
    //        assertEquals(0.52, Double.valueOf(coverages.get(2)), 0.01);
    //        assertEquals(0.58, Double.valueOf(coverages.get(3)), 0.02);
    //        assertEquals(0.88, Double.valueOf(coverages.get(4)), 0.01);
    //        assertEquals(1.00, Double.valueOf(coverages.get(5)), 0.00);
    //        assertEquals(1.00, Double.valueOf(coverages.get(6)), 0.00);
    assertTrue(Double.valueOf(coverages.get(0)) > 0.0);
    assertTrue(Double.valueOf(coverages.get(1)) > 0.0);
    assertTrue(Double.valueOf(coverages.get(2)) > 0.0);
    assertTrue(Double.valueOf(coverages.get(3)) > 0.0);
    assertTrue(Double.valueOf(coverages.get(4)) > 0.0);
    assertTrue(Double.valueOf(coverages.get(5)) > 0.0);
    assertTrue(Double.valueOf(coverages.get(6)) > 0.0);
}

From source file:com.adito.applications.types.JavasType.java

public void prepare(ServerLauncher launcher, ServerLauncherEvents events, XMLElement element)
        throws IOException {

    if (events != null)
        events.debug("Processing <" + element.getName() + "> for java application type");

    this.launcher = launcher;
    this.events = events;

    if (element.getName().equals("java")) {

        String jre = (String) element.getAttribute("jre");

        if (events != null)
            events.debug("Checking our version against the required application version " + jre);

        if (!ServerLauncher.checkVersion(jre)) {
            throw new IOException("Application requires Java Runtime Environment " + jre);
        }//w ww. j a v a2  s  .c o m

        /**
         * LDP - Don't reset the classpath as this stops extended extensions
         * (such as the agent extension itself) from adding addtional
         * classpath entries.
         */
        if (SystemProperties.get("java.version").startsWith("1.1")
                && !SystemProperties.get("java.vendor").startsWith("Microsoft"))
            classpath = SystemProperties.get("java.home") + File.pathSeparator + "lib" + File.pathSeparator
                    + "classes.zip";

        Enumeration e = element.enumerateChildren();

        while (e.hasMoreElements()) {
            XMLElement el = (XMLElement) e.nextElement();

            if (el.getName().equalsIgnoreCase("classpath")) {
                buildClassPath(el);
            } else if (el.getName().equalsIgnoreCase("main")) {
                mainclass = (String) el.getAttribute("class");
                if (events != null)
                    events.debug("Main class is " + mainclass);
                String dir = (String) el.getAttribute("dir");
                if (events != null)
                    events.debug("Dir is " + dir);
                if (dir != null) {
                    workingDir = new File(launcher.replaceTokens(dir));
                } else {
                    workingDir = null;
                }
                buildProgramArguments(el);
            }
        }

        if (events != null)
            events.debug("Finished preparing application descriptor.");
    } else {
        if (events != null)
            events.debug("Ignoring <" + element.getName() + "> tag as it is not a java application tag");
    }

}