Search in sources :

Example 76 with FileSystem

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

the class CloudStorageFileSystemTest method testListFiles.

@Test
public void testListFiles() throws IOException {
    try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
        List<Path> goodPaths = new ArrayList<>();
        List<Path> paths = new ArrayList<>();
        goodPaths.add(fs.getPath("dir/angel"));
        goodPaths.add(fs.getPath("dir/alone"));
        paths.add(fs.getPath("dir/dir2/another_angel"));
        paths.add(fs.getPath("atroot"));
        paths.addAll(goodPaths);
        goodPaths.add(fs.getPath("dir/dir2/"));
        for (Path path : paths) {
            Files.write(path, ALONE.getBytes(UTF_8));
        }
        List<Path> got = new ArrayList<>();
        for (Path path : Files.newDirectoryStream(fs.getPath("/dir/"))) {
            got.add(path);
        }
        assertThat(got).containsExactlyElementsIn(goodPaths);
        // Must also work with relative path
        got.clear();
        for (Path path : Files.newDirectoryStream(fs.getPath("dir/"))) {
            got.add(path);
        }
        assertThat(got).containsExactlyElementsIn(goodPaths);
    }
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 77 with FileSystem

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

the class CloudStorageFileSystemTest method testGetPath.

@Test
public void testGetPath() throws IOException {
    try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
        assertThat(fs.getPath("/angel").toString()).isEqualTo("/angel");
        assertThat(fs.getPath("/angel").toUri().toString()).isEqualTo("gs://bucket/angel");
    }
}
Also used : FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Example 78 with FileSystem

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

the class CloudStorageFileSystemTest method testDeleteEmptiedFolder.

@Test
public void testDeleteEmptiedFolder() 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"));
        for (Path path : paths) {
            Files.write(path, ALONE.getBytes(UTF_8));
        }
        Files.delete(fs.getPath("dir/angel"));
        Files.deleteIfExists(fs.getPath("dir/dir2/another_angel"));
        // delete folder (trailing slash is required)
        Path dir2 = fs.getPath("dir/dir2/");
        Files.deleteIfExists(dir2);
        Path dir = fs.getPath("dir/");
        Files.deleteIfExists(dir);
    // We can't check Files.exists on a folder (since GCS fakes folders)
    }
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 79 with FileSystem

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

the class CloudStorageFileSystemTest method testNullness.

@Test
public void testNullness() throws IOException, NoSuchMethodException, SecurityException {
    try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"))) {
        NullPointerTester tester = new NullPointerTester().ignore(CloudStorageFileSystem.class.getMethod("equals", Object.class)).setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT).setDefault(StorageOptions.class, LocalStorageHelper.getOptions());
        tester.testAllPublicStaticMethods(CloudStorageFileSystem.class);
        tester.testAllPublicInstanceMethods(fs);
    }
}
Also used : FileSystem(java.nio.file.FileSystem) NullPointerTester(com.google.common.testing.NullPointerTester) Test(org.junit.Test)

Example 80 with FileSystem

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

the class CloudStorageFileSystemProviderTest method testIsDirectory.

@Test
public void testIsDirectory() throws Exception {
    try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://doodle"))) {
        assertThat(Files.isDirectory(fs.getPath(""))).isTrue();
        assertThat(Files.isDirectory(fs.getPath("/"))).isTrue();
        assertThat(Files.isDirectory(fs.getPath("."))).isTrue();
        assertThat(Files.isDirectory(fs.getPath("./"))).isTrue();
        assertThat(Files.isDirectory(fs.getPath("cat/.."))).isTrue();
        assertThat(Files.isDirectory(fs.getPath("hello/cat/.."))).isTrue();
        assertThat(Files.isDirectory(fs.getPath("cat/../"))).isTrue();
        assertThat(Files.isDirectory(fs.getPath("hello/cat/../"))).isTrue();
    }
}
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