Search in sources :

Example 56 with Path

use of java.nio.file.Path in project druid by druid-io.

the class CompressionUtilsTest method testGoodZipStream.

@Test
public void testGoodZipStream() throws IOException {
    final File tmpDir = temporaryFolder.newFolder("testGoodZipStream");
    final File zipFile = new File(tmpDir, "compressionUtilTest.zip");
    CompressionUtils.zip(testDir, new FileOutputStream(zipFile));
    final File newDir = new File(tmpDir, "newDir");
    newDir.mkdir();
    CompressionUtils.unzip(new FileInputStream(zipFile), newDir);
    final Path newPath = Paths.get(newDir.getAbsolutePath(), testFile.getName());
    Assert.assertTrue(newPath.toFile().exists());
    try (final FileInputStream inputStream = new FileInputStream(newPath.toFile())) {
        assertGoodDataStream(inputStream);
    }
}
Also used : Path(java.nio.file.Path) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 57 with Path

use of java.nio.file.Path in project druid by druid-io.

the class CompressionUtilsTest method testGoodZipCompressUncompress.

@Test
public void testGoodZipCompressUncompress() throws IOException {
    final File tmpDir = temporaryFolder.newFolder("testGoodZipCompressUncompress");
    final File zipFile = new File(tmpDir, "compressionUtilTest.zip");
    try {
        CompressionUtils.zip(testDir, zipFile);
        final File newDir = new File(tmpDir, "newDir");
        newDir.mkdir();
        CompressionUtils.unzip(zipFile, newDir);
        final Path newPath = Paths.get(newDir.getAbsolutePath(), testFile.getName());
        Assert.assertTrue(newPath.toFile().exists());
        try (final FileInputStream inputStream = new FileInputStream(newPath.toFile())) {
            assertGoodDataStream(inputStream);
        }
    } finally {
        if (zipFile.exists()) {
            zipFile.delete();
        }
        if (tmpDir.exists()) {
            tmpDir.delete();
        }
    }
}
Also used : Path(java.nio.file.Path) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 58 with Path

use of java.nio.file.Path in project che by eclipse.

the class FlywaySchemaInitializerTest method createFile.

private static Path createFile(String filepath, String content) throws URISyntaxException, IOException {
    final Path path = targetDir().resolve(Paths.get(filepath));
    if (!Files.exists(path.getParent())) {
        Files.createDirectories(path.getParent());
    }
    Files.write(path, content.getBytes(StandardCharsets.UTF_8));
    return path;
}
Also used : Path(java.nio.file.Path)

Example 59 with Path

use of java.nio.file.Path in project che by eclipse.

the class ResourcesFinderTest method findsScriptsOnFileSystem.

@Test
public void findsScriptsOnFileSystem() throws Exception {
    final List<Path> paths = createFiles("finder-sql-files/1.0/1.sql", "finder-sql-files/1.0/2.sql", "finder-sql-files/2.0/1.sql", "finder-sql-files/2.0/postgresql/1.sql");
    cleanAfter.addAll(paths);
    final Path finderSqlFiles = paths.get(0).getParent().getParent();
    final String fsLocation = "filesystem:" + finderSqlFiles.toAbsolutePath();
    flyway.setLocations(fsLocation);
    final Set<String> locations = findResources(flyway).get(fsLocation);
    assertEquals(locations, newHashSet(finderSqlFiles.resolve("1.0").resolve("1.sql").toString(), finderSqlFiles.resolve("1.0").resolve("2.sql").toString(), finderSqlFiles.resolve("2.0").resolve("1.sql").toString(), finderSqlFiles.resolve("2.0").resolve("postgresql").resolve("1.sql").toString()));
}
Also used : Path(java.nio.file.Path) Test(org.testng.annotations.Test)

Example 60 with Path

use of java.nio.file.Path in project ghostdriver by detro.

the class GetFixtureHttpRequestCallback method call.

@Override
public void call(HttpServletRequest req, HttpServletResponse res) throws IOException {
    // Construct path to the file
    Path filePath = FileSystems.getDefault().getPath(FIXTURE_PATH, req.getPathInfo());
    // If the file exists
    if (filePath.toFile().exists()) {
        try {
            // Set Content Type
            res.setContentType(filePathToMimeType(filePath.toString()));
            // Read and write to response
            Files.copy(filePath, res.getOutputStream());
            return;
        } catch (NoSuchFileException nsfe) {
            LOG.warning(nsfe.getClass().getName());
        } catch (IOException ioe) {
            LOG.warning(ioe.getClass().getName());
        } catch (RuntimeException re) {
            LOG.warning(re.getClass().getName());
        }
    }
    LOG.warning("Fixture NOT FOUND: " + filePath);
    //< Not Found
    res.sendError(404);
}
Also used : Path(java.nio.file.Path) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Aggregations

Path (java.nio.file.Path)4893 Test (org.junit.Test)1960 IOException (java.io.IOException)829 File (java.io.File)445 SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)334 BuildTarget (com.facebook.buck.model.BuildTarget)320 ArrayList (java.util.ArrayList)313 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 InputStream (java.io.InputStream)210 ImmutableList (com.google.common.collect.ImmutableList)175 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 HashMap (java.util.HashMap)159 ImmutableMap (com.google.common.collect.ImmutableMap)157 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)154 Matchers.containsString (org.hamcrest.Matchers.containsString)148 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)147 Map (java.util.Map)146