27 |
27 |
28 import java.nio.file.attribute.BasicFileAttributes; |
28 import java.nio.file.attribute.BasicFileAttributes; |
29 import java.io.Closeable; |
29 import java.io.Closeable; |
30 import java.io.IOException; |
30 import java.io.IOException; |
31 import java.util.ArrayDeque; |
31 import java.util.ArrayDeque; |
|
32 import java.util.Collection; |
32 import java.util.Iterator; |
33 import java.util.Iterator; |
33 import java.util.Set; |
|
34 import sun.nio.fs.BasicFileAttributesHolder; |
34 import sun.nio.fs.BasicFileAttributesHolder; |
35 |
35 |
36 /** |
36 /** |
37 * Walks a file tree, generating a sequence of events corresponding to the files |
37 * Walks a file tree, generating a sequence of events corresponding to the files |
38 * in the tree. |
38 * in the tree. |
162 } |
162 } |
163 } |
163 } |
164 |
164 |
165 /** |
165 /** |
166 * Creates a {@code FileTreeWalker}. |
166 * Creates a {@code FileTreeWalker}. |
167 */ |
167 * |
168 FileTreeWalker(Set<FileVisitOption> options, int maxDepth) { |
168 * @throws IllegalArgumentException |
|
169 * if {@code maxDepth} is negative |
|
170 * @throws ClassCastException |
|
171 * if (@code options} contains an element that is not a |
|
172 * {@code FileVisitOption} |
|
173 * @throws NullPointerException |
|
174 * if {@code options} is {@ocde null} or the options |
|
175 * array contains a {@code null} element |
|
176 */ |
|
177 FileTreeWalker(Collection<FileVisitOption> options, int maxDepth) { |
169 boolean fl = false; |
178 boolean fl = false; |
170 for (FileVisitOption option: options) { |
179 for (FileVisitOption option: options) { |
171 // will throw NPE if options contains null |
180 // will throw NPE if options contains null |
172 switch (option) { |
181 switch (option) { |
173 case FOLLOW_LINKS : fl = true; break; |
182 case FOLLOW_LINKS : fl = true; break; |
174 default: |
183 default: |
175 throw new AssertionError("Should not get here"); |
184 throw new AssertionError("Should not get here"); |
176 } |
185 } |
177 } |
186 } |
|
187 if (maxDepth < 0) |
|
188 throw new IllegalArgumentException("'maxDepth' is negative"); |
|
189 |
178 this.followLinks = fl; |
190 this.followLinks = fl; |
179 this.linkOptions = (fl) ? new LinkOption[0] : |
191 this.linkOptions = (fl) ? new LinkOption[0] : |
180 new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; |
192 new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; |
181 this.maxDepth = maxDepth; |
193 this.maxDepth = maxDepth; |
182 } |
194 } |