src/share/classes/java/nio/file/FileTreeWalker.java

Print this page
rev 7061 : 8006884: (fs) Add Files.list, lines and find
Reviewed-by:
Contributed-by: alan.bateman@oracle.com, henry.jen@oracle.com

*** 27,38 **** import java.nio.file.attribute.BasicFileAttributes; import java.io.Closeable; import java.io.IOException; import java.util.ArrayDeque; import java.util.Iterator; - import java.util.Set; import sun.nio.fs.BasicFileAttributesHolder; /** * Walks a file tree, generating a sequence of events corresponding to the files * in the tree. --- 27,38 ---- import java.nio.file.attribute.BasicFileAttributes; import java.io.Closeable; import java.io.IOException; import java.util.ArrayDeque; + import java.util.Collection; import java.util.Iterator; import sun.nio.fs.BasicFileAttributesHolder; /** * Walks a file tree, generating a sequence of events corresponding to the files * in the tree.
*** 162,182 **** } } /** * Creates a {@code FileTreeWalker}. */ ! FileTreeWalker(Set<FileVisitOption> options, int maxDepth) { boolean fl = false; for (FileVisitOption option: options) { // will throw NPE if options contains null switch (option) { case FOLLOW_LINKS : fl = true; break; default: throw new AssertionError("Should not get here"); } } this.followLinks = fl; this.linkOptions = (fl) ? new LinkOption[0] : new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; this.maxDepth = maxDepth; } --- 162,194 ---- } } /** * Creates a {@code FileTreeWalker}. + * + * @throws IllegalArgumentException + * if {@code maxDepth} is negative + * @throws ClassCastException + * if (@code options} contains an element that is not a + * {@code FileVisitOption} + * @throws NullPointerException + * if {@code options} is {@ocde null} or the options + * array contains a {@code null} element */ ! FileTreeWalker(Collection<FileVisitOption> options, int maxDepth) { boolean fl = false; for (FileVisitOption option: options) { // will throw NPE if options contains null switch (option) { case FOLLOW_LINKS : fl = true; break; default: throw new AssertionError("Should not get here"); } } + if (maxDepth < 0) + throw new IllegalArgumentException("'maxDepth' is negative"); + this.followLinks = fl; this.linkOptions = (fl) ? new LinkOption[0] : new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; this.maxDepth = maxDepth; }