Package org.apache.commons.io.file
Class AccumulatorPathVisitor
java.lang.Object
java.nio.file.SimpleFileVisitor<Path>
org.apache.commons.io.file.SimplePathVisitor
org.apache.commons.io.file.CountingPathVisitor
org.apache.commons.io.file.AccumulatorPathVisitor
- All Implemented Interfaces:
- FileVisitor<Path>,- PathVisitor
Accumulates normalized paths during visitation.
 
Use with care on large file trees as each visited Path element is remembered.
Example
Path dir = PathUtils.current(); // We are interested in files older than one day Instant cutoff = Instant.now().minus(Duration.ofDays(1)); AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); // // Walk one directory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
- Since:
- 2.7
- 
Nested Class SummaryNested ClassesNested classes/interfaces inherited from class org.apache.commons.io.file.CountingPathVisitorCountingPathVisitor.AbstractBuilder<T,B extends CountingPathVisitor.AbstractBuilder<T, B>> 
- 
Constructor SummaryConstructorsConstructorDescriptionDeprecated.AccumulatorPathVisitor(Counters.PathCounters pathCounter) Deprecated.Usebuilder().AccumulatorPathVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter) Deprecated.Usebuilder().AccumulatorPathVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter, IOBiFunction<Path, IOException, FileVisitResult> visitFileFailed) Deprecated.Usebuilder().
- 
Method SummaryModifier and TypeMethodDescriptionbuilder()Builds instances ofAccumulatorPathVisitor.booleanGets a copy of the list of visited directories.Gets a copy of the list of visited files.inthashCode()relativizeDirectories(Path parent, boolean sort, Comparator<? super Path> comparator) Relativizes each directory path withPath.relativize(Path)against the givenparent, optionally sorting the result.relativizeFiles(Path parent, boolean sort, Comparator<? super Path> comparator) Relativizes each file path withPath.relativize(Path)against the givenparent, optionally sorting the result.protected voidupdateDirCounter(Path dir, IOException exc) Updates the counter for visiting the given directory.protected voidupdateFileCounters(Path file, BasicFileAttributes attributes) Updates the counters for visiting the given file.static AccumulatorPathVisitorConstructs a new instance configured with a BigIntegerCounters.PathCounters.static AccumulatorPathVisitorwithBigIntegerCounters(PathFilter fileFilter, PathFilter dirFilter) Constructs a new instance configured with a BigIntegerCounters.PathCounters.static AccumulatorPathVisitorConstructs a new instance configured with a longCounters.PathCounters.static AccumulatorPathVisitorwithLongCounters(PathFilter fileFilter, PathFilter dirFilter) Constructs a new instance configured with a longCounters.PathCounters.Methods inherited from class org.apache.commons.io.file.CountingPathVisitoraccept, getPathCounters, postVisitDirectory, preVisitDirectory, toString, visitFileMethods inherited from class org.apache.commons.io.file.SimplePathVisitorvisitFileFailed
- 
Constructor Details- 
AccumulatorPathVisitorDeprecated.Usebuilder().Constructs a new instance with a noop path counter.- Since:
- 2.9.0
 
- 
AccumulatorPathVisitorDeprecated.Usebuilder().Constructs a new instance that counts file system elements.- Parameters:
- pathCounter- How to count path visits.
 
- 
AccumulatorPathVisitor@Deprecated public AccumulatorPathVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter) Deprecated.Usebuilder().Constructs a new instance.- Parameters:
- pathCounter- How to count path visits.
- fileFilter- Filters which files to count.
- dirFilter- Filters which directories to count.
- Since:
- 2.9.0
 
- 
AccumulatorPathVisitor@Deprecated public AccumulatorPathVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter, IOBiFunction<Path, IOException, FileVisitResult> visitFileFailed) Deprecated.Usebuilder().Constructs a new instance.- Parameters:
- pathCounter- How to count path visits.
- fileFilter- Filters which files to count.
- dirFilter- Filters which directories to count.
- visitFileFailed- Called on- SimplePathVisitor.visitFileFailed(Path, IOException).
- Since:
- 2.12.0
 
 
- 
- 
Method Details- 
builderBuilds instances ofAccumulatorPathVisitor.- Returns:
- a new builder.
- Since:
- 2.19.0
 
- 
withBigIntegerCountersConstructs a new instance configured with a BigIntegerCounters.PathCounters.- Returns:
- a new instance configured with a BigInteger Counters.PathCounters.
- See Also:
 
- 
withBigIntegerCounterspublic static AccumulatorPathVisitor withBigIntegerCounters(PathFilter fileFilter, PathFilter dirFilter) Constructs a new instance configured with a BigIntegerCounters.PathCounters.- Parameters:
- fileFilter- Filters files to accumulate and count.
- dirFilter- Filters directories to accumulate and count.
- Returns:
- a new instance configured with a long Counters.PathCounters.
- Since:
- 2.9.0
- See Also:
 
- 
withLongCountersConstructs a new instance configured with a longCounters.PathCounters.- Returns:
- a new instance configured with a long Counters.PathCounters.
- See Also:
 
- 
withLongCountersConstructs a new instance configured with a longCounters.PathCounters.- Parameters:
- fileFilter- Filters files to accumulate and count.
- dirFilter- Filters directories to accumulate and count.
- Returns:
- a new instance configured with a long Counters.PathCounters.
- Since:
- 2.9.0
- See Also:
 
- 
equals- Overrides:
- equalsin class- CountingPathVisitor
 
- 
getDirListGets a copy of the list of visited directories.- Returns:
- a copy of the list of visited directories.
 
- 
getFileListGets a copy of the list of visited files.- Returns:
- a copy of the list of visited files.
 
- 
hashCode- Overrides:
- hashCodein class- CountingPathVisitor
 
- 
relativizeDirectoriespublic List<Path> relativizeDirectories(Path parent, boolean sort, Comparator<? super Path> comparator) Relativizes each directory path withPath.relativize(Path)against the givenparent, optionally sorting the result.- Parameters:
- parent- A parent path
- sort- Whether to sort
- comparator- How to sort, null uses default sorting.
- Returns:
- A new list
 
- 
relativizeFilesRelativizes each file path withPath.relativize(Path)against the givenparent, optionally sorting the result.- Parameters:
- parent- A parent path
- sort- Whether to sort
- comparator- How to sort, null uses default sorting.
- Returns:
- A new list
 
- 
updateDirCounterDescription copied from class:CountingPathVisitorUpdates the counter for visiting the given directory.- Overrides:
- updateDirCounterin class- CountingPathVisitor
- Parameters:
- dir- the visited directory.
- exc- Encountered exception.
 
- 
updateFileCountersDescription copied from class:CountingPathVisitorUpdates the counters for visiting the given file.- Overrides:
- updateFileCountersin class- CountingPathVisitor
- Parameters:
- file- the visited file.
- attributes- the visited file attributes.
 
 
- 
builder().