private static class FileFinder.Finder extends SimpleFileVisitor<Path>
findFiles(...)
methods to actually
"walk" the directory tree.Modifier and Type | Field and Description |
---|---|
private PathMatcher |
matcher
Pattern matcher.
|
private List<String> |
matches
String representations of matching Paths . |
Constructor and Description |
---|
Finder(String pattern)
Creates a new file searcher.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
done()
Prints the total number of matches to standard out.
|
(package private) void |
find(Path file)
Compare the given file or directory against the glob pattern.
|
FileVisitResult |
preVisitDirectory(Path dir,
BasicFileAttributes attrs)
Invokes the pattern matching method on the given directory.
|
(package private) List<String> |
results()
Returns the matching paths as strings.
|
FileVisitResult |
visitFile(Path file,
BasicFileAttributes attrs)
Invokes pattern matching method on the given file.
|
FileVisitResult |
visitFileFailed(Path file,
IOException exc)
Handle file "visitation" errors.
|
postVisitDirectory
private final PathMatcher matcher
Finder(String pattern)
Please see FileSystem.getPathMatcher(String)
for more
details concerning patterns.
pattern
- Pattern to match against.void find(Path file)
If file
matches, it is added to matches
.
file
- File (or directory) to compare against the glob pattern.results()
void done()
List<String> results()
List
of the matching paths as String
values.public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
visitFile
in interface FileVisitor<Path>
visitFile
in class SimpleFileVisitor<Path>
file
- File in question.attrs
- Attributes of dir
. Not currently used.FileVisitResult.CONTINUE
(for now).public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
preVisitDirectory
in interface FileVisitor<Path>
preVisitDirectory
in class SimpleFileVisitor<Path>
dir
- Directory in question.attrs
- Attributes of dir
. Not currently used.FileVisitResult.CONTINUE
(for now).public FileVisitResult visitFileFailed(Path file, IOException exc)
visitFileFailed
in interface FileVisitor<Path>
visitFileFailed
in class SimpleFileVisitor<Path>
file
- File that could not be "visited".exc
- Exception associated with "visit" to
file
.FileVisitResult.CONTINUE
(for now).