diff --git a/src/examples/java/software/amazon/nio/spi/examples/ListPrefix.java b/src/examples/java/software/amazon/nio/spi/examples/ListPrefix.java index d08f19b8..573b5eb2 100644 --- a/src/examples/java/software/amazon/nio/spi/examples/ListPrefix.java +++ b/src/examples/java/software/amazon/nio/spi/examples/ListPrefix.java @@ -1,11 +1,15 @@ package software.amazon.nio.spi.examples; +import software.amazon.nio.spi.s3.S3FileSystem; +import software.amazon.nio.spi.s3.S3Path; + import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.util.Collections; + +import static java.util.Collections.*; public class ListPrefix { public static void main(String[] args) throws IOException { @@ -15,8 +19,12 @@ public static void main(String[] args) throws IOException { } String prefix = args[0]; - try (final FileSystem fileSystem = FileSystems.newFileSystem(URI.create(prefix), Collections.EMPTY_MAP)) { + try (final FileSystem fileSystem = FileSystems.newFileSystem(URI.create(prefix), emptyMap())) { Path s3Path = fileSystem.getPath(prefix); + + assert fileSystem.getClass().getName().contains("S3FileSystem"); + assert s3Path.getClass().getName().contains("S3Path"); + fileSystem.provider() .newDirectoryStream(s3Path, item -> true) .forEach(path -> System.out.println(path.getFileName())); diff --git a/src/examples/java/software/amazon/nio/spi/examples/WalkFromRoot.java b/src/examples/java/software/amazon/nio/spi/examples/WalkFromRoot.java index 4a6d41c6..60b4aef8 100644 --- a/src/examples/java/software/amazon/nio/spi/examples/WalkFromRoot.java +++ b/src/examples/java/software/amazon/nio/spi/examples/WalkFromRoot.java @@ -8,6 +8,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; +import java.util.stream.Stream; public class WalkFromRoot { @@ -19,14 +20,25 @@ public class WalkFromRoot { * @throws IOException if a communication problem happens with the S3 service. */ public static void main(String[] args) throws IOException { + + if (args.length < 1){ + System.err.println("Provide a bucket name to walk"); + System.exit(1); + } + String bucketName = args[0]; if (!bucketName.startsWith("s3:") && !bucketName.startsWith("s3x:")) { bucketName = "s3://" + bucketName; } - final FileSystem s3 = FileSystems.newFileSystem(URI.create(bucketName), Collections.EMPTY_MAP); + try (FileSystem s3 = FileSystems.newFileSystem(URI.create(bucketName), Collections.emptyMap())) { + + assert s3.getClass().getName().contains("S3FileSystem"); - for (Path rootDir : s3.getRootDirectories()) { - Files.walk(rootDir).forEach(System.out::println); + for (Path rootDir : s3.getRootDirectories()) { + try (Stream pathStream = Files.walk(rootDir)) { + pathStream.forEach(System.out::println); + } + } } } }