Example usage for java.nio.file Path toAbsolutePath

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

Introduction

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

Prototype

Path toAbsolutePath();

Source Link

Document

Returns a Path object representing the absolute path of this path.

Usage

From source file:org.craftercms.studio.impl.v1.image.transformation.ImageMagickTransformer.java

private String createCmdLine(Path sourcePath, Path targetPath, Map<String, String> parameters) {
    StringBuilder cmdLine = new StringBuilder(imgMgkPath);

    cmdLine.append(" ").append(sourcePath.toAbsolutePath().toString());

    String options = MapUtils.getString(parameters, PARAM_OPTIONS);
    if (StringUtils.isNotEmpty(options)) {
        cmdLine.append(" ").append(options);
    }/*from   www  .  j a v  a 2s.  c o  m*/

    cmdLine.append(" ").append(targetPath.toAbsolutePath().toString());

    return cmdLine.toString();
}

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

@Test
public void testExtractZipFile() throws IOException {

    try (Zip zip = new Zip(zipFile, true)) {
        zip.add("1.bin", DUMMY_FILE_CONTENTS);
        zip.add("subdir/2.bin", DUMMY_FILE_CONTENTS);
        zip.addDir("emptydir");
    }/* w w w .ja  v a2  s  .c o  m*/

    Path extractFolder = tmpFolder.newFolder();
    ImmutableList<Path> result = Unzip.extractZipFile(zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(),
            Unzip.ExistingFileMode.OVERWRITE);
    assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("1.bin")));
    Path bin2 = extractFolder.toAbsolutePath().resolve("subdir/2.bin");
    assertTrue(Files.exists(bin2));
    assertTrue(Files.isDirectory(extractFolder.toAbsolutePath().resolve("emptydir")));
    try (InputStream input = Files.newInputStream(bin2)) {
        byte[] buffer = new byte[DUMMY_FILE_CONTENTS.length];
        int bytesRead = input.read(buffer, 0, DUMMY_FILE_CONTENTS.length);
        assertEquals(DUMMY_FILE_CONTENTS.length, bytesRead);
        for (int i = 0; i < DUMMY_FILE_CONTENTS.length; i++) {
            assertEquals(DUMMY_FILE_CONTENTS[i], buffer[i]);
        }
    }
    assertEquals(ImmutableList.of(extractFolder.resolve("1.bin"), extractFolder.resolve("subdir/2.bin")),
            result);
}

From source file:com.qwazr.library.archiver.ArchiverTest.java

@Test
public void extractDir() throws IOException, ArchiveException, CompressorException {
    Path destDir = Files.createTempDirectory("archiverToolTest");

    Assert.assertNotNull(gzipArchiver);/*  w  w w  .  j  a va2s.  c o m*/
    gzipArchiver.decompress_dir("src/test/resources/com/qwazr/library/archiver", "gz",
            destDir.toAbsolutePath().toString());
    Assert.assertTrue(Files.exists(destDir.resolve("test1.tar")));
    Assert.assertTrue(Files.exists(destDir.resolve("test2.tar")));

    Assert.assertNotNull(archiver);
    archiver.extract_dir(destDir.toAbsolutePath().toString(), "tar", destDir.toAbsolutePath().toString(),
            false);
    Assert.assertTrue(Files.exists(destDir.resolve("test1")));
    Assert.assertTrue(Files.exists(destDir.resolve("test2")));
}

From source file:org.apache.nifi.processors.standard.TestGetSFTP.java

@Test
public void testGetSFTPIgnoreDottedFiles() throws IOException {
    emptyTestDirectory();//from  w ww  .java2s .com

    touchFile(sshTestServer.getVirtualFileSystemPath() + "testFile1.txt");
    touchFile(sshTestServer.getVirtualFileSystemPath() + ".testFile2.txt");
    touchFile(sshTestServer.getVirtualFileSystemPath() + "testFile3.txt");
    touchFile(sshTestServer.getVirtualFileSystemPath() + ".testFile4.txt");

    getSFTPRunner.run();

    getSFTPRunner.assertTransferCount(GetSFTP.REL_SUCCESS, 2);

    //Verify non-dotted files were deleted and dotted files were not deleted
    Path file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/testFile1.txt");
    Assert.assertTrue("File not deleted.", !file1.toAbsolutePath().toFile().exists());

    file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/testFile3.txt");
    Assert.assertTrue("File not deleted.", !file1.toAbsolutePath().toFile().exists());

    file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/.testFile2.txt");
    Assert.assertTrue("File deleted.", file1.toAbsolutePath().toFile().exists());

    file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/.testFile4.txt");
    Assert.assertTrue("File deleted.", file1.toAbsolutePath().toFile().exists());

    getSFTPRunner.clearTransferState();
}

From source file:org.sakuli.utils.LoggerInitializer.java

protected String getConfigFile() {
    Path configFile = Paths.get(sakuliProperties.getConfigFolder() + File.separator + LOG_CONFIG_FILE_NAME);
    if (Files.exists(configFile)) {
        return configFile.toAbsolutePath().toString();
    }/*from  w  w w  .  j  av  a2s . c  o m*/
    return null;
}

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

@Test
public void testExtractZipFilePreservesExecutePermissionsAndModificationTime() throws IOException {

    // getFakeTime returs time with some non-zero millis. By doing division and multiplication by
    // 1000 we get rid of that.
    final long time = ZipConstants.getFakeTime() / 1000 * 1000;

    // Create a simple zip archive using apache's commons-compress to store executable info.
    try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
        ZipArchiveEntry entry = new ZipArchiveEntry("test.exe");
        entry.setUnixMode((int) MorePosixFilePermissions.toMode(PosixFilePermissions.fromString("r-x------")));
        entry.setSize(DUMMY_FILE_CONTENTS.length);
        entry.setMethod(ZipEntry.STORED);
        entry.setTime(time);//  w  w  w .j  ava2 s  . co m
        zip.putArchiveEntry(entry);
        zip.write(DUMMY_FILE_CONTENTS);
        zip.closeArchiveEntry();
    }

    // Now run `Unzip.extractZipFile` on our test zip and verify that the file is executable.
    Path extractFolder = tmpFolder.newFolder();
    ImmutableList<Path> result = Unzip.extractZipFile(zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(),
            Unzip.ExistingFileMode.OVERWRITE);
    Path exe = extractFolder.toAbsolutePath().resolve("test.exe");
    assertTrue(Files.exists(exe));
    assertThat(Files.getLastModifiedTime(exe).toMillis(), Matchers.equalTo(time));
    assertTrue(Files.isExecutable(exe));
    assertEquals(ImmutableList.of(extractFolder.resolve("test.exe")), result);
}

From source file:org.apache.nifi.processors.standard.TestGetSFTP.java

@Test
public void testGetSFTPFileBasicRead() throws IOException {
    emptyTestDirectory();/*  w  w w.j a v  a2 s  . c  o  m*/

    touchFile(sshTestServer.getVirtualFileSystemPath() + "testFile1.txt");
    touchFile(sshTestServer.getVirtualFileSystemPath() + "testFile2.txt");
    touchFile(sshTestServer.getVirtualFileSystemPath() + "testFile3.txt");
    touchFile(sshTestServer.getVirtualFileSystemPath() + "testFile4.txt");

    getSFTPRunner.run();

    getSFTPRunner.assertTransferCount(GetSFTP.REL_SUCCESS, 4);

    //Verify files deleted
    for (int i = 1; i < 5; i++) {
        Path file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/testFile" + i + ".txt");
        Assert.assertTrue("File not deleted.", !file1.toAbsolutePath().toFile().exists());
    }

    getSFTPRunner.clearTransferState();
}

From source file:com.indoqa.osgi.embedded.sample.config.SampleConfig.java

private Path initializeDirectory(Path dir) {
    try {/*from w ww . j a v a  2s  . co m*/
        Files.createDirectories(dir);
    } catch (IOException e) {
        throw new EmbeddedOSGiContainerInitializationException(
                "Error while creating directory '" + dir.toAbsolutePath() + "'.", e);
    }
    return dir;
}

From source file:org.elasticsearch.plugins.SitePluginIT.java

@Override
protected Settings nodeSettings(int nodeOrdinal) {
    Path pluginDir = getDataPath("/org/elasticsearch/test_plugins");
    return settingsBuilder().put(super.nodeSettings(nodeOrdinal))
            .put("path.plugins", pluginDir.toAbsolutePath()).put("force.http.enabled", true).build();
}

From source file:fi.johannes.kata.ocr.utils.structs.Filename.java

public Filename(Path filename) throws IOException {
    // TODO Not sure is it even necessary to validate Path, check
    if (CFilePathOperations.validatePath(filename.getFileName().toString())) {
        absolutePath = filename.toAbsolutePath();
        cacheStrings();//from  w w  w.  j a  v  a2  s.c  o  m
    } else {
        throw new IOException();
    }
}