public class AccumulatorPathVisitor extends CountingPathVisitor
Use with care on large file trees as each visited Path element is remembered.
Path dir = Paths.get(""); // We are interested in files older than one day long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000); AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); // // Walk one dir Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk dir tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
Constructor and Description |
---|
AccumulatorPathVisitor()
Constructs a new instance.
|
AccumulatorPathVisitor(Counters.PathCounters pathCounter)
Constructs a new instance that counts file system elements.
|
AccumulatorPathVisitor(Counters.PathCounters pathCounter,
PathFilter fileFilter,
PathFilter dirFilter)
Constructs a new instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
List<Path> |
getDirList()
Gets the list of visited directories.
|
List<Path> |
getFileList()
Gets the list of visited files.
|
int |
hashCode() |
List<Path> |
relativizeDirectories(Path parent,
boolean sort,
Comparator<? super Path> comparator)
Relativizes each directory path with
Path.relativize(Path) against the given parent , optionally
sorting the result. |
List<Path> |
relativizeFiles(Path parent,
boolean sort,
Comparator<? super Path> comparator)
Relativizes each file path with
Path.relativize(Path) against the given parent , optionally
sorting the result. |
protected void |
updateDirCounter(Path dir,
IOException exc)
Updates the counter for visiting the given directory.
|
protected void |
updateFileCounters(Path file,
BasicFileAttributes attributes)
Updates the counters for visiting the given file.
|
static AccumulatorPathVisitor |
withBigIntegerCounters()
Creates a new instance configured with a BigInteger
Counters.PathCounters . |
static AccumulatorPathVisitor |
withBigIntegerCounters(PathFilter fileFilter,
PathFilter dirFilter)
Creates a new instance configured with a BigInteger
Counters.PathCounters . |
static AccumulatorPathVisitor |
withLongCounters()
Creates a new instance configured with a long
Counters.PathCounters . |
static AccumulatorPathVisitor |
withLongCounters(PathFilter fileFilter,
PathFilter dirFilter)
Creates a new instance configured with a long
Counters.PathCounters . |
getPathCounters, postVisitDirectory, preVisitDirectory, toString, visitFile
visitFileFailed
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
visitFileFailed
public AccumulatorPathVisitor()
public AccumulatorPathVisitor(Counters.PathCounters pathCounter)
pathCounter
- How to count path visits.public AccumulatorPathVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter)
pathCounter
- How to count path visits.fileFilter
- Filters which files to count.dirFilter
- Filters which directories to count.public static AccumulatorPathVisitor withBigIntegerCounters()
Counters.PathCounters
.Counters.PathCounters
.public static AccumulatorPathVisitor withBigIntegerCounters(PathFilter fileFilter, PathFilter dirFilter)
Counters.PathCounters
.fileFilter
- Filters files to accumulate and count.dirFilter
- Filters directories to accumulate and count.Counters.PathCounters
.public static AccumulatorPathVisitor withLongCounters()
Counters.PathCounters
.Counters.PathCounters
.public static AccumulatorPathVisitor withLongCounters(PathFilter fileFilter, PathFilter dirFilter)
Counters.PathCounters
.fileFilter
- Filters files to accumulate and count.dirFilter
- Filters directories to accumulate and count.Counters.PathCounters
.public boolean equals(Object obj)
equals
in class CountingPathVisitor
public List<Path> getDirList()
public List<Path> getFileList()
public int hashCode()
hashCode
in class CountingPathVisitor
public List<Path> relativizeDirectories(Path parent, boolean sort, Comparator<? super Path> comparator)
Path.relativize(Path)
against the given parent
, optionally
sorting the result.parent
- A parent pathsort
- Whether to sortcomparator
- How to sort, null uses default sorting.public List<Path> relativizeFiles(Path parent, boolean sort, Comparator<? super Path> comparator)
Path.relativize(Path)
against the given parent
, optionally
sorting the result.parent
- A parent pathsort
- Whether to sortcomparator
- How to sort, null uses default sorting.protected void updateDirCounter(Path dir, IOException exc)
CountingPathVisitor
updateDirCounter
in class CountingPathVisitor
dir
- the visited directory.exc
- Encountered exception.protected void updateFileCounters(Path file, BasicFileAttributes attributes)
CountingPathVisitor
updateFileCounters
in class CountingPathVisitor
file
- the visited file.attributes
- the visited file attributes.Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.