Skip to content

Commit 2af9913

Browse files
Refactor to use Files.list() (#275)
1 parent 74f4d06 commit 2af9913

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/examples/java/software/amazon/nio/spi/examples/ListPrefix.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import java.io.IOException;
44
import java.net.URI;
5+
import java.nio.file.Files;
56
import java.nio.file.Path;
67
import java.nio.file.Paths;
8+
import java.util.stream.Stream;
79

810
public class ListPrefix {
911
public static void main(String[] args) throws IOException {
@@ -12,15 +14,10 @@ public static void main(String[] args) throws IOException {
1214
System.exit(1);
1315
}
1416

15-
String prefix = args[0];
16-
17-
Path s3Path = Paths.get(URI.create(prefix));
18-
19-
assert s3Path.getClass().getName().contains("S3Path");
20-
21-
s3Path.getFileSystem().provider()
22-
.newDirectoryStream(s3Path, item -> true)
23-
.forEach(path -> System.out.println(path.getFileName()));
17+
Path s3Path = Paths.get(URI.create(args[0]));
2418

19+
try (Stream<Path> listed = Files.list(s3Path)) {
20+
listed.forEach(System.out::println);
21+
}
2522
}
2623
}

0 commit comments

Comments
 (0)