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);
}
}
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");
}
}
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)
}
}
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);
}
}
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();
}
}
Aggregations