Example usage for java.nio.file Path resolve

List of usage examples for java.nio.file Path resolve

Introduction

In this page you can find the example usage for java.nio.file Path resolve.

Prototype

default Path resolve(String other) 

Source Link

Document

Converts a given path string to a Path and resolves it against this Path in exactly the manner specified by the #resolve(Path) resolve method.

Usage

From source file:Main.java

private static void addDummyFile(Path directory, String fileName, int size) throws IOException {
    byte[] content = new byte[size];
    for (int i = 0; i < content.length; i++) {
        content[i] = (byte) i;
    }//from www  . j a va  2  s .com

    Files.createDirectories(directory);
    Files.write(directory.resolve(fileName), content);
}

From source file:com.github.anba.es6draft.chakra.ChakraTest.java

private static Map<String, TestSetting> readSettings(Path dir) {
    Path settingsFile = dir.resolve("rlexe.xml");
    if (Files.isRegularFile(settingsFile)) {
        try (Reader reader = bomReader(Files.newInputStream(settingsFile))) {
            Document doc = Resources.xml(reader);
            NodeList elements = doc.getElementsByTagName("default");
            HashMap<String, TestSetting> settingMap = new HashMap<>();
            for (int i = 0, length = elements.getLength(); i < length; ++i) {
                Element element = (Element) elements.item(i);
                String files = element.getElementsByTagName("files").item(0).getTextContent();
                TestSetting setting = new TestSetting();
                NodeList baseline = element.getElementsByTagName("baseline");
                if (baseline.getLength() > 0) {
                    setting.baseline = baseline.item(0).getTextContent();
                }//from w  ww. j  a v  a  2  s .  c  o  m
                NodeList compileFlags = element.getElementsByTagName("compile-flags");
                if (compileFlags.getLength() > 0) {
                    String flags = compileFlags.item(0).getTextContent();
                    setting.disabled = flags.contains("-verbose") || flags.contains("-dump:")
                            || flags.contains("-trace:") || flags.contains("-testtrace:")
                            || flags.contains("-testTrace:");
                }
                settingMap.putIfAbsent(files, setting);
            }
            return settingMap;
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    return Collections.emptyMap();
}

From source file:edu.cwru.jpdg.Javac.java

/**
 * Takes the full package name of the java file to load from the
 * resources (see `Javac.load` for details). It uses `load` to get the
 * file and `javac` to compile it. It then loads up the classes using soot.
 *
 * @returns HashMap : package_name - JavaClass
 *///from w  w  w  .j a v  a 2  s .  c  om
public static HashMap<String, soot.SootClass> classes(String full_name) {
    String[] split = StringUtils.split(full_name, ".");
    String name = split[split.length - 1];
    String basedir = "/tmp";
    javac(basedir, name, load(full_name));
    HashMap<String, soot.SootClass> map = new HashMap<String, soot.SootClass>();

    String cp = System.getenv().get("JAVA_JARS");
    Path dir = Paths.get(cwd).resolve(basedir);
    Path build = dir.resolve("build");
    String base_dir = build.toString();
    List<String> dirs = new ArrayList<String>();
    dirs.add(base_dir);

    soot.Scene S = edu.cwru.jpdg.JPDG.runSoot(cp, dirs, new ArrayList<String>());
    for (soot.SootClass klass : S.getApplicationClasses()) {
        System.out.println(klass);
        map.put(klass.getName(), klass);
    }
    return map;
}

From source file:org.jetbrains.webdemo.backend.executor.ExecutorUtils.java

private static Path storeFilesInTemporaryDirectory(Map<String, byte[]> files) throws IOException {
    Path outputDir = Paths.get(BackendSettings.OUTPUT_DIRECTORY, "tmp", String.valueOf(new Random().nextInt()));
    for (String fileName : files.keySet()) {
        Path filePath = outputDir.resolve(fileName);
        filePath.getParent().toFile().mkdirs();
        Files.write(filePath, files.get(fileName));
    }/*from  ww w .  java  2 s  . c om*/
    return outputDir;
}

From source file:it.sonarlint.cli.tools.SonarlintInstaller.java

private static Path locateScript(String version, Path installPath) {
    String directoryName = "sonarlint-cli-" + version;
    String fileName = SystemUtils.IS_OS_WINDOWS ? "sonarlint.bat" : "sonarlint";

    Path script = installPath.resolve(directoryName).resolve("bin").resolve(fileName);

    if (!Files.exists(script)) {
        throw new IllegalStateException("File does not exist: " + script);
    }/*  w w  w .jav  a  2  s .  c o m*/
    return script;
}

From source file:com.github.horrorho.liquiddonkey.cloud.file.SnapshotDirectory.java

static SnapshotDirectory from(Path base, String udidStr, String snapshotIdStr, boolean isFlat,
        boolean isCombined, String combinedDirectory) {

    SHA1Digest sha1 = new SHA1Digest();

    Path folder = isCombined ? base.resolve(udidStr).resolve(combinedDirectory)
            : base.resolve(udidStr).resolve(snapshotIdStr);

    return isFlat ? new FlatSnapshotDirectory(folder, sha1) : new NonFlatSnapshotDirectory(folder, sha1);
}

From source file:its.tools.SonarlintInstaller.java

private static Path locateScript(String version, Path installPath) {
    String directoryName = "sonarlint-daemon-" + version;
    String fileName = SystemUtils.IS_OS_WINDOWS ? "sonarlint-daemon.bat" : "sonarlint-daemon";

    Path script = installPath.resolve(directoryName).resolve("bin").resolve(fileName);

    if (!Files.exists(script)) {
        throw new IllegalStateException("File does not exist: " + script);
    }//  w ww . ja v  a  2 s  .  co  m
    return script;
}

From source file:com.ttech.cordovabuild.infrastructure.archive.ArchiveUtils.java

private static void extractArchive(Path localPath, ArchiveInputStream ais) throws IOException {
    ArchiveEntry ae;/*from w w  w.j  ava 2  s  . c om*/
    while ((ae = ais.getNextEntry()) != null) {
        if (ae.isDirectory()) {
            continue;
        }
        Path filePath = localPath.resolve(ae.getName());
        if (!filePath.getParent().equals(localPath))
            Files.createDirectories(filePath.getParent());
        try (OutputStream outputStream = Files.newOutputStream(filePath)) {
            IOUtils.copy(ais, outputStream);
        }
    }
}

From source file:com.surevine.gateway.scm.git.jgit.TestUtility.java

public static LocalRepoBean createTestRepo() throws Exception {
    final String projectKey = "test_" + UUID.randomUUID().toString();
    final String repoSlug = "testRepo";
    final String remoteURL = "ssh://fake_url";
    final Path repoPath = Paths.get(PropertyUtil.getGitDir(), "local_scm", projectKey, repoSlug);
    Files.createDirectories(repoPath);
    final Repository repo = new FileRepository(repoPath.resolve(".git").toFile());
    repo.create();//  www. j a  v  a  2s  .c  om
    final StoredConfig config = repo.getConfig();
    config.setString("remote", "origin", "url", remoteURL);
    config.save();

    final LocalRepoBean repoBean = new LocalRepoBean();
    repoBean.setProjectKey(projectKey);
    repoBean.setSlug(repoSlug);
    repoBean.setLocalBare(false);
    repoBean.setSourcePartner("partner");

    final Git git = new Git(repo);

    for (int i = 0; i < 3; i++) {
        final String filename = "newfile" + i + ".txt";
        Files.write(repoPath.resolve(filename), Arrays.asList("Hello World"), StandardCharsets.UTF_8,
                StandardOpenOption.CREATE, StandardOpenOption.APPEND);
        git.add().addFilepattern(filename).call();
        git.commit().setMessage("Added " + filename).call();
    }

    git.checkout().setName("master").call();

    repo.close();
    return repoBean;
}

From source file:net.certiv.antlr.project.util.Utils.java

/**
 * Move all files from the source directory to the destination directory.
 * /*from  ww  w.  ja va  2  s .  co m*/
 * @param source
 *            the source directory
 * @param dest
 *            the destination directory
 * @return
 * @throws IOException
 */
public static boolean moveAllFiles(File source, File dest) throws IOException {
    if (source == null || dest == null)
        throw new IllegalArgumentException("Directory cannot be null");
    if (!source.exists() || !source.isDirectory())
        throw new IOException("Source directory must exist: " + source.getCanonicalPath());

    dest.mkdirs();
    if (!dest.exists() || !dest.isDirectory())
        throw new IOException("Destination directory must exist: " + dest.getCanonicalPath());

    Path srcDir = source.toPath();
    Path dstDir = dest.toPath();
    DirectoryStream<Path> ds = Files.newDirectoryStream(srcDir);
    int tot = 0;
    for (Path src : ds) {
        Files.copy(src, dstDir.resolve(src.getFileName()), REPLACE_EXISTING);
        tot++;
    }
    Log.info(Utils.class, "Moved " + tot + " files");
    return false;
}