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:io.sledge.core.impl.installer.SledgePackageConfigurer.java

@Override
public InputStream configure(InputStream packageStream, String packageName, Properties props) {
    InputStream resultStream = packageStream;

    try {/*w ww  .ja v a  2 s . c  o  m*/
        Path sledgeTmpDir = createSledgeTmpDirectoryIfNotExists();
        deleteZipFile(sledgeTmpDir, packageName);
        Path configurationZipPackagePath = sledgeTmpDir.resolve(packageName);
        createNewZipfileWithReplacedPlaceholders(packageStream, configurationZipPackagePath, props);
        resultStream = new FileInputStream(configurationZipPackagePath.toFile());
    } catch (IOException e) {
        log.error("Could not configure package: " + packageName, e);
    } finally {
        try {
            packageStream.reset();
            packageStream.close();
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }

    return resultStream;
}

From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java

private void backupFile() throws IOException {
    final Path sourceFile = picture.getFile();
    final String parentPath = sourceFile.getParent().toString();
    final String hashedPath = DigestUtils.md5Hex(parentPath + backupId);

    final Path targetDir = BACKUP_DIR.resolve(hashedPath);
    Files.createDirectories(targetDir);

    Files.copy(sourceFile, targetDir.resolve(sourceFile.getFileName()));
}

From source file:cc.kave.commons.pointsto.evaluation.events.MRREvaluation.java

public void exportResults(Path dir, ResultExporter exporter) throws IOException {
    Path resultFile = dir.resolve(getClass().getSimpleName() + ".txt");
    exporter.export(resultFile, results.entrySet().stream().map(entry -> {
        ICoReTypeName type = entry.getKey().getLeft();
        return new String[] { CoReNames.vm2srcQualifiedType(type), entry.getKey().getMiddle(),
                entry.getKey().getRight(), String.format(Locale.US, "%.5f", entry.getValue()) };
    }));/*  w  ww.j ava2s. c  o m*/

    Path numQueriesFile = dir.resolve(getClass().getSimpleName() + ".nq.txt");
    exporter.export(numQueriesFile,
            numQueries.entrySet().stream()
                    .map(entry -> new String[] { CoReNames.vm2srcQualifiedType(entry.getKey().getLeft()),
                            entry.getKey().getRight(), Integer.toString(entry.getValue()) }));

    Path zeroExtractedQueriesFile = dir.resolve(getClass().getSimpleName() + ".zeq.txt");
    exporter.export(zeroExtractedQueriesFile, zeroExtractedQueries.entrySet().stream()
            .map(entry -> new String[] { entry.getKey(), Integer.toString(entry.getValue()) }));

    Path prunedUsagesFile = dir.resolve(getClass().getSimpleName() + ".pruned.txt");
    exporter.export(prunedUsagesFile, prunedUsages.stream().map(entry -> new String[] { entry.getLeft(),
            CoReNames.vm2srcQualifiedType(entry.getMiddle()), entry.getRight().toString() }));

    exporter.export(dir.resolve(getClass().getSimpleName() + ".mst.txt"),
            missingStoreTypes.entrySet().stream().map(entry -> {
                String typeNames = entry.getValue().stream().map(CoReNames::vm2srcQualifiedType)
                        .collect(Collectors.joining(","));
                return new String[] { entry.getKey(), typeNames };
            }));
}

From source file:com.cloudbees.clickstack.util.Files2.java

/**
 * TODO recopy file permissions//from   ww  w . j  av  a2 s. com
 * <p/>
 * Uncompress the specified tgz file to the specified destination directory.
 * Replaces any files in the destination, if they already exist.
 *
 * @param tgzFile the name of the zip file to extract
 * @param destDir the directory to unzip to
 * @throws RuntimeIOException
 */
public static void untgz(@Nonnull Path tgzFile, @Nonnull Path destDir) throws RuntimeIOException {
    try {
        //if the destination doesn't exist, create it
        if (Files.notExists(destDir)) {
            logger.trace("Create dir: {}", destDir);
            Files.createDirectories(destDir);
        }

        TarArchiveInputStream in = new TarArchiveInputStream(
                new GzipCompressorInputStream(Files.newInputStream(tgzFile)));

        TarArchiveEntry entry;
        while ((entry = in.getNextTarEntry()) != null) {
            if (entry.isDirectory()) {
                Path dir = destDir.resolve(entry.getName());
                logger.trace("Create dir {}", dir);
                Files.createDirectories(dir);
            } else {
                Path file = destDir.resolve(entry.getName());
                logger.trace("Create file {}: {} bytes", file, entry.getSize());
                OutputStream out = Files.newOutputStream(file);
                IOUtils.copy(in, out);
                out.close();
            }
        }

        in.close();
    } catch (IOException e) {
        throw new RuntimeIOException("Exception expanding " + tgzFile + " to " + destDir, e);
    }
}

From source file:com.facebook.buck.zip.ZipStepTest.java

@Test
public void overwritingAnExistingZipFileIsAnError() throws IOException {
    Path parent = tmp.newFolder("zipstep");
    Path out = parent.resolve("output.zip");

    try (Zip zip = new Zip(out, true)) {
        zip.add("file1.txt", "");
    }/*from  w  ww. j a v a 2s  . c om*/

    ZipStep step = new ZipStep(filesystem, Paths.get("zipstep"), ImmutableSet.of(), false,
            ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir"));
    assertEquals(1, step.execute(TestExecutionContext.newInstance()).getExitCode());
}

From source file:com.facebook.buck.zip.ZipStepTest.java

@Test
public void shouldBeAbleToJunkPaths() throws IOException {
    Path parent = tmp.newFolder("zipstep");
    Path out = parent.resolve("output.zip");

    Path toZip = tmp.newFolder("zipdir");
    Files.createDirectories(toZip.resolve("child"));
    Files.createFile(toZip.resolve("child/file1.txt"));

    ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), true,
            ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir"));
    assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode());

    try (Zip zip = new Zip(out, false)) {
        assertEquals(ImmutableSet.of("file1.txt"), zip.getFileNames());
    }/*from   w  ww.j av  a2  s .  c  om*/
}

From source file:com.facebook.buck.zip.ZipStepTest.java

@Test
public void shouldCreateANewZipFileFromScratch() throws IOException {
    Path parent = tmp.newFolder("zipstep");
    Path out = parent.resolve("output.zip");

    Path toZip = tmp.newFolder("zipdir");
    Files.createFile(toZip.resolve("file1.txt"));
    Files.createFile(toZip.resolve("file2.txt"));
    Files.createFile(toZip.resolve("file3.txt"));

    ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), false,
            ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir"));
    assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode());

    try (Zip zip = new Zip(out, false)) {
        assertEquals(ImmutableSet.of("file1.txt", "file2.txt", "file3.txt"), zip.getFileNames());
    }//from   ww w  . j  ava  2 s .  co  m
}

From source file:com.facebook.buck.zip.ZipStepTest.java

@Test
public void zipMaintainsExecutablePermissions() throws IOException {
    assumeTrue(Platform.detect() != Platform.WINDOWS);

    Path parent = tmp.newFolder("zipstep");
    Path toZip = tmp.newFolder("zipdir");
    Path file = toZip.resolve("foo.sh");
    ImmutableSet<PosixFilePermission> filePermissions = ImmutableSet.of(PosixFilePermission.OWNER_READ,
            PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ,
            PosixFilePermission.OTHERS_READ);
    Files.createFile(file, PosixFilePermissions.asFileAttribute(filePermissions));
    Path outputZip = parent.resolve("output.zip");
    ZipStep step = new ZipStep(filesystem, outputZip, ImmutableSet.of(), false,
            ZipCompressionLevel.MIN_COMPRESSION_LEVEL, Paths.get("zipdir"));
    assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode());

    Path destination = tmp.newFolder("output");
    Unzip.extractZipFile(outputZip, destination, Unzip.ExistingFileMode.OVERWRITE);
    assertTrue(Files.isExecutable(destination.resolve("foo.sh")));
}

From source file:com.facebook.buck.zip.ZipStepTest.java

@Test
public void willOnlyIncludeEntriesInThePathsArgumentIfAnyAreSet() throws IOException {
    Path parent = tmp.newFolder("zipstep");
    Path out = parent.resolve("output.zip");

    Path toZip = tmp.newFolder("zipdir");

    Files.createFile(toZip.resolve("file1.txt"));
    Files.createFile(toZip.resolve("file2.txt"));
    Files.createFile(toZip.resolve("file3.txt"));

    ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"),
            ImmutableSet.of(Paths.get("zipdir/file2.txt")), false,
            ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir"));
    assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode());

    try (Zip zip = new Zip(out, false)) {
        assertEquals(ImmutableSet.of("file2.txt"), zip.getFileNames());
    }/*w w  w  . ja v  a  2s  .c o  m*/
}

From source file:org.ng200.openolympus.controller.task.TaskFilesystemManipulatingController.java

@PreAuthorize(SecurityExpressionConstants.IS_ADMIN)
private void extractZipFile(final InputStream zipFile, final Path destination) throws Exception {
    try (ArchiveInputStream input = new ArchiveStreamFactory()
            .createArchiveInputStream(new BufferedInputStream(zipFile))) {
        ArchiveEntry entry;/*from   w  w  w. j a  v  a  2  s.  c  o  m*/
        while ((entry = input.getNextEntry()) != null) {
            final Path dest = destination.resolve(entry.getName());
            if (entry.isDirectory()) {
                FileAccess.createDirectories(dest);
            } else {
                FileAccess.createDirectories(dest.getParent());
                FileAccess.createFile(dest);
                Files.copy(input, dest, StandardCopyOption.REPLACE_EXISTING);
            }
        }
    }
}