Search in sources :

Example 81 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 82 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)

Example 83 with FileSystem

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

the class CloudStorageFileSystemProviderTest method testNullness.

@Test
public void testNullness() throws Exception {
    try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://blood"))) {
        NullPointerTester tester = new NullPointerTester();
        tester.ignore(CloudStorageFileSystemProvider.class.getMethod("equals", Object.class));
        tester.setDefault(URI.class, URI.create("gs://blood"));
        tester.setDefault(Path.class, fs.getPath("and/one"));
        tester.setDefault(OpenOption.class, CREATE);
        tester.setDefault(CopyOption.class, COPY_ATTRIBUTES);
        // can't do that, setStorageOptions accepts a null argument.
        // TODO(jart): Figure out how to re-enable this.
        // tester.testAllPublicStaticMethods(CloudStorageFileSystemProvider.class);
        tester.testAllPublicInstanceMethods(new CloudStorageFileSystemProvider());
    }
}
Also used : FileSystem(java.nio.file.FileSystem) NullPointerTester(com.google.common.testing.NullPointerTester) Test(org.junit.Test)

Example 84 with FileSystem

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

the class ITGcsNio method testDeleteRecursive.

@Test
public void testDeleteRecursive() throws IOException {
    try (FileSystem fs = getTestBucket()) {
        List<Path> paths = new ArrayList<>();
        paths.add(fs.getPath("Racine"));
        paths.add(fs.getPath("playwrights/Moliere"));
        paths.add(fs.getPath("playwrights/French/Corneille"));
        for (Path path : paths) {
            Files.write(path, FILE_CONTENTS, UTF_8);
        }
        deleteRecursive(fs.getPath("playwrights/"));
        assertThat(Files.exists(fs.getPath("playwrights/Moliere"))).isFalse();
        assertThat(Files.exists(fs.getPath("playwrights/French/Corneille"))).isFalse();
        assertThat(Files.exists(fs.getPath("Racine"))).isTrue();
        Files.deleteIfExists(fs.getPath("Racine"));
        assertThat(Files.exists(fs.getPath("Racine"))).isFalse();
    }
}
Also used : Path(java.nio.file.Path) CloudStorageFileSystem(com.google.cloud.storage.contrib.nio.CloudStorageFileSystem) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 85 with FileSystem

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

the class ITGcsNio method testListFiles.

@Test
public void testListFiles() throws IOException {
    try (FileSystem fs = getTestBucket()) {
        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) {
            fillFile(storage, path.toString(), SML_SIZE);
        }
        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) CloudStorageFileSystem(com.google.cloud.storage.contrib.nio.CloudStorageFileSystem) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

FileSystem (java.nio.file.FileSystem)156 Path (java.nio.file.Path)109 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 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 URI (java.net.URI)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