Package org.apache.commons.io.file
Class CleaningPathVisitor
- java.lang.Object
-
- java.nio.file.SimpleFileVisitor<java.nio.file.Path>
-
- org.apache.commons.io.file.SimplePathVisitor
-
- org.apache.commons.io.file.CountingPathVisitor
-
- org.apache.commons.io.file.CleaningPathVisitor
-
- All Implemented Interfaces:
java.nio.file.FileVisitor<java.nio.file.Path>
,PathVisitor
public class CleaningPathVisitor extends CountingPathVisitor
Deletes files but not directories as a visit proceeds.- Since:
- 2.7
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
overrideReadOnly
private java.lang.String[]
skip
-
Fields inherited from class org.apache.commons.io.file.CountingPathVisitor
EMPTY_STRING_ARRAY
-
-
Constructor Summary
Constructors Constructor Description CleaningPathVisitor(Counters.PathCounters pathCounter, java.lang.String... skip)
Constructs a new visitor that deletes files except for the files and directories explicitly given.CleaningPathVisitor(Counters.PathCounters pathCounter, DeleteOption[] deleteOption, java.lang.String... skip)
Constructs a new visitor that deletes files except for the files and directories explicitly given.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
accept(java.nio.file.Path path)
Returns true to process the given path, false if not.boolean
equals(java.lang.Object obj)
int
hashCode()
java.nio.file.FileVisitResult
preVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attributes)
java.nio.file.FileVisitResult
visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attributes)
static CountingPathVisitor
withBigIntegerCounters()
Creates a new instance configured with a BigIntegerCounters.PathCounters
.static CountingPathVisitor
withLongCounters()
Creates a new instance configured with a longCounters.PathCounters
.-
Methods inherited from class org.apache.commons.io.file.CountingPathVisitor
getPathCounters, postVisitDirectory, toString, updateDirCounter, updateFileCounters
-
-
-
-
Constructor Detail
-
CleaningPathVisitor
public CleaningPathVisitor(Counters.PathCounters pathCounter, DeleteOption[] deleteOption, java.lang.String... skip)
Constructs a new visitor that deletes files except for the files and directories explicitly given.- Parameters:
pathCounter
- How to count visits.deleteOption
- How deletion is handled.skip
- The files to skip deleting.- Since:
- 2.8.0
-
CleaningPathVisitor
public CleaningPathVisitor(Counters.PathCounters pathCounter, java.lang.String... skip)
Constructs a new visitor that deletes files except for the files and directories explicitly given.- Parameters:
pathCounter
- How to count visits.skip
- The files to skip deleting.
-
-
Method Detail
-
withBigIntegerCounters
public static CountingPathVisitor withBigIntegerCounters()
Creates a new instance configured with a BigIntegerCounters.PathCounters
.- Returns:
- a new instance configured with a BigInteger
Counters.PathCounters
.
-
withLongCounters
public static CountingPathVisitor withLongCounters()
Creates a new instance configured with a longCounters.PathCounters
.- Returns:
- a new instance configured with a long
Counters.PathCounters
.
-
accept
private boolean accept(java.nio.file.Path path)
Returns true to process the given path, false if not.- Parameters:
path
- the path to test.- Returns:
- true to process the given path, false if not.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classCountingPathVisitor
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classCountingPathVisitor
-
preVisitDirectory
public java.nio.file.FileVisitResult preVisitDirectory(java.nio.file.Path dir, java.nio.file.attribute.BasicFileAttributes attributes) throws java.io.IOException
- Specified by:
preVisitDirectory
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Overrides:
preVisitDirectory
in classCountingPathVisitor
- Throws:
java.io.IOException
-
visitFile
public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attributes) throws java.io.IOException
- Specified by:
visitFile
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Overrides:
visitFile
in classCountingPathVisitor
- Throws:
java.io.IOException
-
-