Search in sources :

Example 71 with FileSystem

use of java.nio.file.FileSystem in project beam by apache.

the class ApexYarnLauncherTest method testCreateJar.

@Test
public void testCreateJar() throws Exception {
    File baseDir = new File("./target/testCreateJar");
    File srcDir = new File(baseDir, "src");
    String file1 = "file1";
    FileUtils.forceMkdir(srcDir);
    FileUtils.write(new File(srcDir, file1), "file1");
    File jarFile = new File(baseDir, "test.jar");
    ApexYarnLauncher.createJar(srcDir, jarFile);
    Assert.assertTrue("exists: " + jarFile, jarFile.exists());
    URI uri = URI.create("jar:" + jarFile.toURI());
    final Map<String, ?> env = Collections.singletonMap("create", "true");
    try (final FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
        Assert.assertTrue("manifest", Files.isRegularFile(zipfs.getPath(JarFile.MANIFEST_NAME)));
        Assert.assertTrue("file1", Files.isRegularFile(zipfs.getPath(file1)));
    }
}
Also used : FileSystem(java.nio.file.FileSystem) Matchers.containsString(org.hamcrest.Matchers.containsString) JarFile(java.util.jar.JarFile) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 72 with FileSystem

use of java.nio.file.FileSystem in project ratpack by ratpack.

the class JarFileEphemeralBaseDir method getJarPath.

private static Path getJarPath(File jar) {
    URI uri = URI.create("jar:" + jar.toURI().toString());
    Map<String, String> env = new HashMap<>();
    env.put("create", "true");
    FileSystem fileSystem;
    try {
        fileSystem = FileSystems.newFileSystem(uri, env);
    } catch (IOException e) {
        throw uncheck(e);
    }
    return fileSystem.getPath("/");
}
Also used : HashMap(java.util.HashMap) FileSystem(java.nio.file.FileSystem) IOException(java.io.IOException) URI(java.net.URI)

Example 73 with FileSystem

use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.

the class CloudStorageFileSystemTest method testDeleteEmptyFolder.

@Test
public void testDeleteEmptyFolder() throws IOException {
    try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
        List<Path> paths = new ArrayList<>();
        paths.add(fs.getPath("dir/angel"));
        paths.add(fs.getPath("dir/dir2/another_angel"));
        paths.add(fs.getPath("atroot"));
        for (Path path : paths) {
            Files.write(path, ALONE.getBytes(UTF_8));
        }
        // we can delete non-existent folders, because they are not represented on disk anyways.
        Files.delete(fs.getPath("ghost/"));
        Files.delete(fs.getPath("dir/ghost/"));
        Files.delete(fs.getPath("dir/dir2/ghost/"));
        // likewise, deleteIfExists works.
        Files.deleteIfExists(fs.getPath("ghost/"));
        Files.deleteIfExists(fs.getPath("dir/ghost/"));
        Files.deleteIfExists(fs.getPath("dir/dir2/ghost/"));
    }
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 74 with FileSystem

use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.

the class CloudStorageFileSystemTest method testMatcher.

@Test
public void testMatcher() throws IOException {
    try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
        String pattern1 = "glob:*.java";
        PathMatcher javaFileMatcher = fs.getPathMatcher(pattern1);
        assertMatches(fs, javaFileMatcher, "a.java", true);
        assertMatches(fs, javaFileMatcher, "a.text", false);
        assertMatches(fs, javaFileMatcher, "folder/c.java", true);
        assertMatches(fs, javaFileMatcher, "d", false);
        String pattern2 = "glob:*.{java,text}";
        PathMatcher javaAndTextFileMatcher = fs.getPathMatcher(pattern2);
        assertMatches(fs, javaAndTextFileMatcher, "a.java", true);
        assertMatches(fs, javaAndTextFileMatcher, "a.text", true);
        assertMatches(fs, javaAndTextFileMatcher, "folder/c.java", true);
        assertMatches(fs, javaAndTextFileMatcher, "d", false);
    }
}
Also used : PathMatcher(java.nio.file.PathMatcher) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 75 with FileSystem

use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.

the class CloudStorageFileSystemTest method testDeleteFullFolder.

@Test
public void testDeleteFullFolder() throws IOException {
    thrown.expect(CloudStoragePseudoDirectoryException.class);
    try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
        Files.write(fs.getPath("dir/angel"), ALONE.getBytes(UTF_8));
        // we cannot delete existing folders if they contain something
        Files.delete(fs.getPath("dir/"));
    }
}
Also used : FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

FileSystem (java.nio.file.FileSystem)159 Path (java.nio.file.Path)112 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 URI (java.net.URI)11 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4