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:org.evosuite.executionmode.ListClasses.java

private static void listClassesPrefix(String prefix) {

    String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();

    Set<String> classes = new LinkedHashSet<>();

    for (String classPathElement : cp.split(File.pathSeparator)) {
        classes.addAll(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT())
                .getAllClasses(classPathElement, prefix, false));
        try {//from  w w  w  .j  av  a 2s .  c o  m
            ClassPathHacker.addFile(classPathElement);
        } catch (IOException e) {
            // Ignore?
        }
    }
    for (String sut : classes) {
        try {
            if (ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT())
                    .isClassAnInterface(sut)) {
                continue;
            }
        } catch (IOException e) {
            LoggingUtils.getEvoLogger().error("Could not load class: " + sut);
            continue;
        }
        LoggingUtils.getEvoLogger().info(sut);
    }
}

From source file:com.denimgroup.threadfix.framework.filefilter.ClassAnnotationBasedFileFilter.java

/**
 * This should just proxy to the other method
 *///ww  w . jav a2  s.  c o  m
@Override
public boolean accept(@Nonnull File file, String name) {
    return accept(new File(file.getAbsolutePath() + File.pathSeparator + name));
}

From source file:edu.stanford.muse.index.PDFHandler.java

/** handles a pdf file. philosophy: create png files and text file in topLevelFromDir
 * and copy them to webappTopLevelDir.//from   w  w  w.  j ava 2  s.c  o m
 * because webappTopLevelDir could get wiped out when the web server restarts.
 * always copies pdf and png's.
 * updates docCache with contents and header if needed. */
private PDFDocument handlePDF(DocCache docCache, String topLevelFromDir, String webappTopLevelDir,
        String libDir, String userKey, String datasetTitle, int num, String description, String section,
        File pdfFile) {

    // x.pdf: text goes to x.pdf.txt, and page images to go x.pdf.1.png, x.pdf.2.png, etc
    String filename = pdfFile.getName(); // not full path, just the name of the file
    String topLevelToDir = webappTopLevelDir + File.separator + datasetTitle;
    String txtFilename = filename + ".txt";
    String pagePNGPrefix = filename + ".";

    // working dirs are just <top level>/<section>
    String workingFromDir = topLevelFromDir + File.separator + section;
    String workingToDir = topLevelToDir + File.separator + section;

    // create the working dir for this section if it doesn't exist
    new File(workingToDir + File.separator + "dummy").mkdirs();

    // given the pdf, create a .txt and .png files for each page.
    // copy the pdf and png's to the todir because the browser may need to access them directly
    // the txt file never needs to be directly accessible.
    try {
        if (!pdfFile.exists())
            throw new FileNotFoundException();

        // copy the pdf
        Util.copyFileIfItDoesntExist(workingFromDir, workingToDir, filename);

        String txtFileFromFullPath = workingFromDir + File.separator + txtFilename;
        String cp = libDir + File.separator + "log4j-1.2.15.jar" + File.pathSeparator;
        cp += libDir + File.separator + "pdfbox-1.1.0.jar" + File.pathSeparator;
        cp += libDir + File.separator + "fontbox-1.1.0.jar" + File.pathSeparator;
        cp += libDir + File.separator + "commons-logging-1.1.1.jar" + File.pathSeparator;

        // generate the txt file if it doesn't exist
        // we launch in a separate vm because it has a tendency to crash the VM
        if (!docCache.hasContents(datasetTitle, num)) {
            String cmd = "java -cp " + cp + " org.apache.pdfbox.ExtractText " + filename + " " + txtFilename;
            Util.run_command(cmd, workingFromDir);
            if (!new File(txtFileFromFullPath).exists()) {
                // create a dummy file
                FileOutputStream fos = new FileOutputStream(txtFileFromFullPath);
                fos.close();
            }

            String contents = Util.getFileContents(workingFromDir + File.separator + txtFilename);
            docCache.saveContents(contents, datasetTitle, num);
        }

        // handle images
        File dirFile = new File(workingFromDir);
        File files[] = dirFile
                .listFiles(new Util.MyFilenameFilter(workingFromDir + File.separator + pagePNGPrefix, ".png"));
        if (files.length == 0) {
            // png files not generated
            // resolution 200 makes the images readable
            String cmd = "java -cp " + cp + " org.apache.pdfbox.PDFToImage -imageType png -outputPrefix "
                    + pagePNGPrefix + " -resolution 100 " + filename;
            Util.run_command(cmd, workingFromDir);
            files = dirFile.listFiles(
                    new Util.MyFilenameFilter(workingFromDir + File.separator + pagePNGPrefix, ".png"));
            if (files.length == 0) {
                // if still no files, something must have failed. copy a sorry file.

                String dummyFile = workingFromDir + pagePNGPrefix + ".0.png";
                Util.copy_file(webappTopLevelDir + File.separator + "images" + File.separator + "sorry.png",
                        dummyFile);
                files = new File[1];
                files[0] = new File(dummyFile);
            }
        }

        Util.sortFilesByTime(files);

        // copy over PNG Files
        for (File f : files)
            Util.copyFileIfItDoesntExist(workingFromDir, workingToDir, f.getName());

        // note it's important to escape url's below.
        // this is because the dataset or section etc can contain special chars like '#'
        // but we can't use URLEncoder.encode because that causes problems by converting each space to a +.
        // this breaks the relative URL in the browser.
        // therefore, we reuse the "light encoding" of Util.URLEncodeFilePath
        // may need fixing if other special chars pop up
        List<String> relativeURLsForImages = new ArrayList<String>();
        for (@SuppressWarnings("unused")
        File f : files) {
            String relativeURL = userKey + "/" + datasetTitle + "/" + section + "/" + filename;
            //            relativeURL = URLEncoder.encode(relativeURL, "UTF-8");
            relativeURL = Util.URLEncodeFilePath(relativeURL);
            relativeURLsForImages.add(relativeURL);
        }
        String relativeURLForPDF = userKey + "/" + datasetTitle + "/" + section + "/" + filename;
        //      relativeURLForPDF = URLEncoder.encode(relativeURLForPDF, "UTF-8");
        relativeURLForPDF = Util.URLEncodeFilePath(relativeURLForPDF);

        PDFDocument doc = new PDFDocument(num, "PDF", section, relativeURLForPDF, relativeURLsForImages);
        // text contents will remain in topLevelFromDir
        // sanitize path to ensure we escape odd chars like # and ? in the file path
        doc.url = docCache.getContentURL(datasetTitle, num);
        if (!docCache.hasHeader(datasetTitle, num))
            docCache.saveHeader(doc, datasetTitle, num);
        return doc;

        //         cmd = "java -cp " + cp + "/ org.apache.pdfbox.ExtractImages -prefix " + filename + " " + filename;
        //         Util.run_command(cmd, workingDir);
    } catch (Exception e) {
        Util.print_exception(e, log);
        return null;
    }
}

From source file:com.impetus.kundera.classreading.ClasspathReader.java

/**
 * Uses the java.class.path system property to obtain a list of URLs that
 * represent the CLASSPATH//from   w w w  . j  ava2  s. co m
 * 
 * @return the URl[]
 */
@SuppressWarnings("deprecation")
@Override
public final URL[] findResourcesByClasspath() {
    List<URL> list = new ArrayList<URL>();
    String classpath = System.getProperty("java.class.path");
    StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);

    while (tokenizer.hasMoreTokens()) {
        String path = tokenizer.nextToken();

        File fp = new File(path);
        if (!fp.exists())
            throw new ResourceReadingException("File in java.class.path does not exist: " + fp);
        try {
            list.add(fp.toURL());
        } catch (MalformedURLException e) {
            throw new ResourceReadingException(e);
        }
    }
    return list.toArray(new URL[list.size()]);
}

From source file:com.facebook.hiveio.mapreduce.output.WritingTool.java

/**
 * set hive configuration/*from www.java 2s  . co  m*/
 *
 * @param conf Configuration
 */
private void adjustConfigurationForHive(Configuration conf) {
    // when output partitions are used, workers register them to the
    // metastore at cleanup stage, and on HiveConf's initialization, it
    // looks for hive-site.xml.
    addToStringCollection(conf, "tmpfiles", conf.getClassLoader().getResource("hive-site.xml").toString());

    // Or, more effectively, we can provide all the jars client needed to
    // the workers as well
    String[] hadoopJars = System.getenv("HADOOP_CLASSPATH").split(File.pathSeparator);
    List<String> hadoopJarURLs = Lists.newArrayList();
    for (String jarPath : hadoopJars) {
        File file = new File(jarPath);
        if (file.exists() && file.isFile()) {
            String jarURL = file.toURI().toString();
            hadoopJarURLs.add(jarURL);
        }
    }
    addToStringCollection(conf, "tmpjars", hadoopJarURLs);
}

From source file:com.haulmont.cuba.core.sys.AbstractScripting.java

public AbstractScripting(JavaClassLoader javaClassLoader, Configuration configuration,
        SpringBeanLoader springBeanLoader) {
    this.javaClassLoader = javaClassLoader;
    this.springBeanLoader = springBeanLoader;
    globalConfig = configuration.getConfig(GlobalConfig.class);
    groovyClassPath = globalConfig.getConfDir() + File.pathSeparator;

    String classPathProp = AppContext.getProperty("cuba.groovyClassPath");
    if (StringUtils.isNotBlank(classPathProp)) {
        String[] strings = classPathProp.split(";");
        for (String string : strings) {
            if (!groovyClassPath.contains(string.trim() + File.pathSeparator))
                groovyClassPath = groovyClassPath + string.trim() + File.pathSeparator;
        }//w  ww  .  j  a  v  a 2s.  c o m
    }

    String importProp = AppContext.getProperty("cuba.groovyEvaluatorImport");
    if (StringUtils.isNotBlank(importProp)) {
        String[] strings = importProp.split("[,;]");
        for (String string : strings) {
            imports.add(string.trim());
        }
    }
}

From source file:ffx.ui.FFXExec.java

private void setEnv() {
    path = MainPanel.ffxDir.getAbsolutePath();
    classpath = MainPanel.classpath;//  w w w. ja v  a 2 s  .c  o m
    // java.home should be the jre directory.
    ld_library_path = System.getProperty("java.home", ".");
    if (!SystemUtils.IS_OS_WINDOWS) {
        ld_library_path = ld_library_path + "/lib/i386/client:" + ld_library_path + "/lib/i386:"
                + ld_library_path + "/lib/i386/native_threads";
    } else {
        ld_library_path = ld_library_path + "\\bin\\client";
        path = path + File.pathSeparator + ld_library_path;
    }
}

From source file:org.apache.pig.test.TestPredeployedJar.java

@Test
public void testPredeployedJarsProperty() throws ExecException {
    Properties p = new Properties();
    p.setProperty("pig.predeployed.jars", "zzz");
    PigServer pigServer = new PigServer(ExecType.LOCAL, p);

    Assert.assertTrue(pigServer.getPigContext().predeployedJars.contains("zzz"));

    p = new Properties();
    p.setProperty("pig.predeployed.jars", "aaa" + File.pathSeparator + "bbb");
    pigServer = new PigServer(ExecType.LOCAL, p);

    Assert.assertTrue(pigServer.getPigContext().predeployedJars.contains("aaa"));
    Assert.assertTrue(pigServer.getPigContext().predeployedJars.contains("bbb"));

    Assert.assertFalse(pigServer.getPigContext().predeployedJars.contains("zzz"));
}

From source file:com.orange.clara.cloud.servicedbdumper.acceptance.AcceptanceExternalTest.java

protected boolean isCfCliAvailableInPath() {
    String exec = "cf";
    return Stream.of(System.getenv("PATH").split(Pattern.quote(File.pathSeparator))).map(Paths::get)
            .anyMatch(path -> Files.exists(path.resolve(exec)));
}

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

static URL[] constructUrlsFromClasspath(String classpath) throws MalformedURLException {
    List<URL> urls = new ArrayList<URL>();
    for (String element : classpath.split(File.pathSeparator)) {
        if (element.endsWith("/*")) {
            String dir = element.substring(0, element.length() - 1);
            File[] files = new File(dir).listFiles(JAR_FILENAME_FILTER);
            if (files != null) {
                for (File file : files) {
                    urls.add(file.toURI().toURL());
                }/*from  w  w  w .  j  a va  2 s  . c o  m*/
            }
        } else {
            File file = new File(element);
            if (file.exists()) {
                urls.add(new File(element).toURI().toURL());
            }
        }
    }
    return urls.toArray(new URL[urls.size()]);
}