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:io.hops.tensorflow.Client.java

private String addResource(FileSystem fs, ApplicationId appId, String srcPath, String dstDir, String dstName,
        DistributedCacheList distCache, Map<String, LocalResource> localResources, StringBuilder pythonPath)
        throws IOException {
    Path src = new Path(srcPath);

    if (dstDir == null) {
        dstDir = ".";
    }//w w  w  . j  a  v  a  2s .c  o m
    if (dstName == null) {
        dstName = src.getName();
    }

    Path baseDir = new Path(fs.getHomeDirectory(), Constants.YARNTF_STAGING + "/" + appId.toString());
    String dstPath;
    if (dstDir.startsWith(".")) {
        dstPath = dstName;
    } else {
        dstPath = dstDir + "/" + dstName;
    }
    Path dst = new Path(baseDir, dstPath);

    LOG.info("Copying from local filesystem: " + src + " -> " + dst);
    fs.copyFromLocalFile(src, dst);
    FileStatus dstStatus = fs.getFileStatus(dst);

    if (distCache != null) {
        LOG.info("Adding to distributed cache: " + srcPath + " -> " + dstPath);
        distCache.add(new DistributedCacheList.Entry(dstPath, dst.toUri(), dstStatus.getLen(),
                dstStatus.getModificationTime()));
    }

    if (localResources != null) {
        LOG.info("Adding to local environment: " + srcPath + " -> " + dstPath);
        LocalResource resource = LocalResource.newInstance(ConverterUtils.getYarnUrlFromURI(dst.toUri()),
                LocalResourceType.FILE, LocalResourceVisibility.APPLICATION, dstStatus.getLen(),
                dstStatus.getModificationTime());
        localResources.put(dstPath, resource);
    }

    if (pythonPath != null) {
        pythonPath.append(File.pathSeparator).append(dstPath);
    }

    return dstName;
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

private void saveRecentHexFileList() {
    StringBuilder sb = new StringBuilder(128);
    if (recentHexFileList != null) {
        int k = recentHexFileList.listModel.getSize() - 1;
        for (int index = 0; index <= k; index++) {
            File file = recentHexFileList.listModel.getElementAt(k - index);
            if (sb.length() > 0) {
                sb.append(File.pathSeparator);
            }//  w w  w  .  java 2 s  .  co  m
            sb.append(file.getPath());
        }
        Preferences p = Preferences.userNodeForPackage(RecentFileList.class);
        p.put("RecentHexFileList.fileList", sb.toString());
    }
}

From source file:eu.chainfire.opendelta.UpdateService.java

private String findInitialFile(List<DeltaInfo> deltas, String possibleMatch, boolean[] needsProcessing) {
    // Find the currently flashed ZIP, or a newer one

    DeltaInfo firstDelta = deltas.get(0);

    updateState(STATE_ACTION_SEARCHING, null, null, null, null, null);

    String initialFile = null;/*  www  .  j ava2 s.  c o m*/

    // Check if an original flashable ZIP is in our preferred location
    String expectedLocation = config.getPathBase() + firstDelta.getIn().getName();
    DeltaInfo.FileSizeMD5 match = null;
    if (expectedLocation.equals(possibleMatch)) {
        match = firstDelta.getIn().match(new File(expectedLocation), false, null);
        if (match != null) {
            initialFile = possibleMatch;
        }
    }

    if (match == null) {
        match = firstDelta.getIn().match(new File(expectedLocation), true,
                getMD5Progress(STATE_ACTION_SEARCHING_MD5, firstDelta.getIn().getName()));
        if (match != null) {
            initialFile = expectedLocation;
        }
    }
    updateState(STATE_ACTION_SEARCHING, null, null, null, null, null);

    // If the user flashed manually, the file is probably not in our
    // preferred location (assuming it wasn't sideloaded), so search
    // the storages for it.
    if (initialFile == null) {
        // Primary external storage ( == internal storage)
        initialFile = findZIPOnSD(firstDelta.getIn(), Environment.getExternalStorageDirectory());

        if (initialFile == null) {
            // Search secondary external storages ( == sdcards, OTG drives, etc)                 
            String secondaryStorages = System.getenv("SECONDARY_STORAGE");
            if ((secondaryStorages != null) && (secondaryStorages.length() > 0)) {
                String[] storages = TextUtils.split(secondaryStorages, File.pathSeparator);
                for (String storage : storages) {
                    initialFile = findZIPOnSD(firstDelta.getIn(), new File(storage));
                    if (initialFile != null) {
                        break;
                    }
                }
            }
        }

        if (initialFile != null) {
            match = firstDelta.getIn().match(new File(initialFile), false, null);
        }
    }

    if ((needsProcessing != null) && (needsProcessing.length > 0)) {
        needsProcessing[0] = (initialFile != null) && (match != firstDelta.getIn().getStore());
    }

    return initialFile;
}

From source file:org.apache.jasper.JspC.java

private void initClassLoader(JspCompilationContext clctxt) throws IOException {

    classPath = getClassPath();//from   w ww . java  2  s.  com

    ClassLoader jspcLoader = getClass().getClassLoader();
    if (jspcLoader instanceof AntClassLoader) {
        classPath += File.pathSeparator + ((AntClassLoader) jspcLoader).getClasspath();
    }

    // Turn the classPath into URLs
    ArrayList urls = new ArrayList();
    StringTokenizer tokenizer = new StringTokenizer(classPath, File.pathSeparator);
    while (tokenizer.hasMoreTokens()) {
        String path = tokenizer.nextToken();
        try {
            File libFile = new File(path);
            urls.add(libFile.toURL());
        } catch (IOException ioe) {
            // Failing a toCanonicalPath on a file that
            // exists() should be a JVM regression test,
            // therefore we have permission to freak uot
            throw new RuntimeException(ioe.toString());
        }
    }

    File webappBase = new File(uriRoot);
    if (webappBase.exists()) {
        File classes = new File(webappBase, "/WEB-INF/classes");
        try {
            if (classes.exists()) {
                classPath = classPath + File.pathSeparator + classes.getCanonicalPath();
                urls.add(classes.getCanonicalFile().toURL());
            }
        } catch (IOException ioe) {
            // failing a toCanonicalPath on a file that
            // exists() should be a JVM regression test,
            // therefore we have permission to freak out
            throw new RuntimeException(ioe.toString());
        }
        File lib = new File(webappBase, "/WEB-INF/lib");
        if (lib.exists() && lib.isDirectory()) {
            String[] libs = lib.list();
            for (int i = 0; i < libs.length; i++) {
                if (libs[i].length() < 5)
                    continue;
                String ext = libs[i].substring(libs[i].length() - 4);
                if (!".jar".equalsIgnoreCase(ext)) {
                    if (".tld".equalsIgnoreCase(ext)) {
                        log.warn("TLD files should not be placed in " + "/WEB-INF/lib");
                    }
                    continue;
                }
                try {
                    File libFile = new File(lib, libs[i]);
                    classPath = classPath + File.pathSeparator + libFile.getCanonicalPath();
                    urls.add(libFile.getCanonicalFile().toURL());
                } catch (IOException ioe) {
                    // failing a toCanonicalPath on a file that
                    // exists() should be a JVM regression test,
                    // therefore we have permission to freak out
                    throw new RuntimeException(ioe.toString());
                }
            }
        }
    }

    // What is this ??
    urls.add(new File(clctxt.getRealPath("/")).getCanonicalFile().toURL());

    URL urlsA[] = new URL[urls.size()];
    urls.toArray(urlsA);
    loader = new URLClassLoader(urlsA, this.getClass().getClassLoader());
    Thread.currentThread().setContextClassLoader(loader);
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

private void loadRecentHexFileList() {
    Preferences p = Preferences.userNodeForPackage(RecentFileList.class);
    String listOfFiles = p.get("RecentHexFileList.fileList", null);
    if (fc == null) {
        String savedPath = prefs.get("MRUHexFolder", "");
        File MRUHexFolder = new File(savedPath);
        fc = new JFileChooser(MRUHexFolder);
        recentHexFileList = new RecentFileList(fc);
        if (listOfFiles != null) {
            String[] files = listOfFiles.split(File.pathSeparator);
            for (String fileRef : files) {
                File file = new File(fileRef);
                if (file.exists()) {
                    recentHexFileList.listModel.add(file);
                }/* w ww.j a  v a 2 s .  co m*/
            }
        }
        fc.setAccessory(recentHexFileList);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    }
}

From source file:com.openddal.test.BaseTestCase.java

/**
 * Get the classpath list used to execute java -cp ...
 *
 * @return the classpath list//  w ww  .ja va  2s. com
 */
protected String getClassPath() {
    return "bin" + File.pathSeparator + "temp" + File.pathSeparator + ".";
}

From source file:ca.weblite.xmlvm.XMLVM.java

/**
 * Try to just generate c source files on the changes.  If the destination directory
 * doesn't exist, then it will still perform a clean build.
 * @throws IOException //w  w  w .  j  a  v  a 2s  .  c  o  m
 */
public void doRegularBuild(XmlvmCallback callback) throws IOException {
    try {
        //if (getJavac() == null) {
        //    setJavac((Javac) getProject().createTask("javac"));
        //}
        Javac javac = (Javac) getProject().createTask("javac");
        File xmlvmDir = this.getXmlvmCacheDir("xmlvm");

        // Create a temporary directory as a destination for javac 
        File tmpBuild = File.createTempFile("build", "build");
        tmpBuild.delete();
        tmpBuild.mkdir();

        // Create a temporary directory to contain only the .java files that
        // have changed.
        File changedSrcDir = setupChangedSourcesDir();
        System.out.println("Found " + changedSrcDir.list().length + " changed files");

        javac.setDestdir(tmpBuild);

        javac.setSrcdir(new Path(getProject(), changedSrcDir.getAbsolutePath()));
        try {
            System.out.println("Classpath currently " + javac.getClasspath());
            System.out.println("Adding to classpath: " + getClassPath());
            if (!getClassPath().equals(javac.getClasspath())) {
                javac.setClasspath(getClassPath());
            }
        } catch (Exception ex) {
            System.out.println(getClassPath());
            throw ex;
        }
        //javac.getClasspath().add(new Path(getProject(), getJavaBuildDir().getAbsolutePath()));
        System.out.println("Java build dir is " + getJavaBuildDir());
        System.out.println("Running javac on changed sources");
        System.out.println("Src dir is " + javac.getSrcdir());
        //javac.setFork(true);
        javac.setVerbose(true);
        javac.setFailonerror(true);

        javac.execute();

        // Update the dependency graph for the changed classes.
        System.out.println("Updating dependency graph...");
        this.updateDependencyGraph(tmpBuild, xmlvmDir);

        // Copy the compiled files to the intermediate build dir

        System.out.println("Copying compiled sources to " + getJavaBuildDir());
        Copy copy = (Copy) getProject().createTask("copy");
        copy.setTodir(getJavaBuildDir());
        FileSet fs = new FileSet();
        fs.setDir(tmpBuild);
        fs.setIncludes("**");
        copy.addFileset(fs);
        copy.setOverwrite(true);
        copy.execute();

        // Now let's find out which classes may need to be updated due to our
        // changes
        Set<String> changedClasses = getChangedClassNames();
        System.out
                .println("Found " + changedClasses.size() + " changed classes.  Looking for dirty classes...");
        Set<String> dirtyClasses = collectDirtyClasses(changedClasses);

        System.out.println("Found " + dirtyClasses.size() + " dirty classes.");

        // Now try to find the dirty classes
        Set<String> found = new HashSet<String>();
        System.out.println("Locating dirty classes and copying to " + tmpBuild);
        Path searchPath = new Path(getProject(), tmpBuild.getAbsolutePath());
        searchPath.add(javac.getClasspath());
        this.findClassesInPath(searchPath, dirtyClasses, found, tmpBuild);

        if (found.size() != dirtyClasses.size()) {

            Set<String> missing = new HashSet<String>();
            missing.addAll(dirtyClasses);
            missing.removeAll(found);
            System.out.println("Missing classes : " + missing);
            System.out.println("Classpath is " + javac.getClasspath());
            System.out.println("Missing include " + missing);
            System.out.println("Failed to find all dirty classes that need to be compiled : " + found.size()
                    + " vs " + dirtyClasses.size());

        }

        // Now we should have all we need to generate our C source files
        // Delete the changed source dir, since we don't need it anymore
        System.out.println("Deleting " + changedSrcDir + ".  We don't need it anymore.");
        Delete del = (Delete) getProject().createTask("delete");
        del.setDir(changedSrcDir);
        del.execute();

        File intermediateOut = this.getXmlvmCacheDir("c");
        System.out.print("Deleting intermediate build directory...");
        FileUtils.deleteDirectory(intermediateOut);
        System.out.println("Finished");

        intermediateOut.mkdirs();

        //System.out.println("Intermediates: ");
        //for ( File f : tmpOutput.listFiles()){
        //    System.out.println(f);
        //}

        if (tmpBuild.list().length < 5) {
            System.out.println(Arrays.asList(tmpBuild.list()));
        }
        System.out.println("Converting " + tmpBuild.list().length + " xmlvm files to c source files....");
        System.out.println("Input Path is " + tmpBuild.getAbsolutePath());
        System.out.println("Output Path is " + intermediateOut.getAbsolutePath());
        System.out
                .println("Libraries is " + javac.getClasspath().toString().replaceAll(File.pathSeparator, ","));

        // XMLVM seems to copy files from 'libraries' into the 'in' directory
        // which means we always get the old version.
        // We need to copy to the ios/build/classes directory.
        Copy copy2 = (Copy) getProject().createTask("copy");

        callback.beforeXmlvm(tmpBuild, intermediateOut);

        this.runXmlvm(new String[] { "--in=" + tmpBuild.getAbsolutePath(),
                "--out=" + intermediateOut.getAbsolutePath(), "--target=c",
                "--libraries=" + javac.getClasspath().toString().replaceAll(File.pathSeparator, ","),
                "--c-source-extension=m", //"--debug=all",
                "--disable-vtable-optimizations", });

        callback.afterXmlvm(tmpBuild, intermediateOut);
        //if ( true )throw new IOException("test point");

        System.out.println(Arrays.asList(intermediateOut.list()));

        del = (Delete) getProject().createTask("delete");
        del.setDir(tmpBuild);
        del.execute();

        System.out.print("Removing constant pool dependencies...");
        ConstantPoolHelper.removeConstantPoolDependencies(intermediateOut);
        System.out.println("Finished.");

        System.out.print("Fixing vtable references...");
        VtableHelper.fixVtableReferences(getProject(), intermediateOut, getDest());
        System.out.println("Finished.");

        System.out.print("Copying " + dirtyClasses.size() + " changed classes to " + getDest() + "...");
        copyClasses(dirtyClasses, intermediateOut, getDest());
        System.out.println("Finished.");

        //copyChangedSource(intermediateOut, getDest());

    } catch (Exception ex) {
        Logger.getLogger(XMLVM.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.cloud.storage.resource.NfsSecondaryStorageResource.java

public Answer execute(final DownloadSnapshotFromS3Command cmd) {

    final S3TO s3 = cmd.getS3();
    final String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
    final Long accountId = cmd.getAccountId();
    final Long volumeId = cmd.getVolumeId();

    try {/*from w ww . j  a  va2 s .  c om*/

        executeWithNoWaitLock(determineSnapshotLockId(accountId, volumeId), new Callable<Void>() {

            @Override
            public Void call() throws Exception {

                final String directoryName = determineSnapshotLocalDirectory(secondaryStorageUrl, accountId,
                        volumeId);

                String result = createLocalDir(directoryName);
                if (result != null) {
                    throw new InternalErrorException(format(
                            "Failed to create directory %1$s during S3 snapshot download.", directoryName));
                }

                final String snapshotFileName = determineSnapshotBackupFilename(cmd.getSnapshotUuid());
                final String key = determineSnapshotS3Key(accountId, volumeId, snapshotFileName);
                final File targetFile = S3Utils.getFile(s3, s3.getBucketName(), key,
                        _storage.getFile(directoryName), new FileNamingStrategy() {

                            @Override
                            public String determineFileName(String key) {
                                return snapshotFileName;
                            }

                        });

                if (cmd.getParent() != null) {

                    final String parentPath = join(File.pathSeparator, directoryName,
                            determineSnapshotBackupFilename(cmd.getParent()));
                    result = setVhdParent(targetFile.getAbsolutePath(), parentPath);
                    if (result != null) {
                        throw new InternalErrorException(
                                format("Failed to set the parent for backup %1$s to %2$s due to %3$s.",
                                        targetFile.getAbsolutePath(), parentPath, result));
                    }

                }

                return null;

            }

        });

        return new Answer(cmd, true,
                format("Succesfully retrieved volume id %1$s for account id %2$s to %3$s from S3.", volumeId,
                        accountId, secondaryStorageUrl));

    } catch (Exception e) {
        final String errMsg = format(
                "Failed to retrieve volume id %1$s for account id %2$s to %3$s from S3 due to exception %4$s",
                volumeId, accountId, secondaryStorageUrl, e.getMessage());
        s_logger.error(errMsg);
        return new Answer(cmd, false, errMsg);
    }

}

From source file:com.adito.boot.Util.java

/**
 * Get the class path from a class loader (must be an instance
 * of a {@link java.net.URLClassLoader}.
 * //from   ww  w.  ja va  2  s.  c o  m
 * @param classLoader
 * @return class path
 */
public static String getClassPath(ClassLoader classLoader) {
    StringBuffer buf = new StringBuffer();
    if (classLoader instanceof URLClassLoader) {
        URLClassLoader urlc = (URLClassLoader) classLoader;
        URL[] urls = urlc.getURLs();
        for (int i = 0; i < urls.length; i++) {
            if (urls[i].getProtocol().equals("file")) {
                File f = new File(Util.urlDecode(urls[i].getPath()));
                if (buf.length() > 0) {
                    buf.append(File.pathSeparator);
                }
                buf.append(f.getPath());
            }
        }
    }
    return buf.toString();
}

From source file:com.cloud.storage.resource.NfsSecondaryStorageResource.java

private String determineSnapshotLocalDirectory(final String secondaryStorageUrl, final Long accountId,
        final Long volumeId) {
    return join(File.pathSeparator, getRootDir(secondaryStorageUrl), SNAPSHOT_ROOT_DIR, accountId, volumeId);
}