Class DeletingVisitor
- java.lang.Object
-
- java.nio.file.SimpleFileVisitor<java.nio.file.Path>
-
- org.apache.logging.log4j.core.appender.rolling.action.DeletingVisitor
-
- All Implemented Interfaces:
java.nio.file.FileVisitor<java.nio.file.Path>
public class DeletingVisitor extends java.nio.file.SimpleFileVisitor<java.nio.file.Path>FileVisitor that deletes files that are accepted by all PathFilters. Directories are ignored.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.file.PathbasePathprivate static LoggerLOGGERprivate java.util.List<? extends PathCondition>pathConditionsprivate booleantestMode
-
Constructor Summary
Constructors Constructor Description DeletingVisitor(java.nio.file.Path basePath, java.util.List<? extends PathCondition> pathConditions, boolean testMode)Constructs a new DeletingVisitor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddelete(java.nio.file.Path file)Deletes the specified file.booleanisTestMode()Returnstrueif files are not deleted even when all conditions accept a path,falseotherwise.java.nio.file.FileVisitResultvisitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs)java.nio.file.FileVisitResultvisitFileFailed(java.nio.file.Path file, java.io.IOException ioException)
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
-
basePath
private final java.nio.file.Path basePath
-
testMode
private final boolean testMode
-
pathConditions
private final java.util.List<? extends PathCondition> pathConditions
-
-
Constructor Detail
-
DeletingVisitor
public DeletingVisitor(java.nio.file.Path basePath, java.util.List<? extends PathCondition> pathConditions, boolean testMode)Constructs a new DeletingVisitor.- Parameters:
basePath- used to relativize pathspathConditions- objects that need to confirm whether a file can be deletedtestMode- if true, files are not deleted but instead a message is printed to the status logger at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
-
-
Method Detail
-
visitFile
public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs) throws java.io.IOException- Specified by:
visitFilein interfacejava.nio.file.FileVisitor<java.nio.file.Path>- Overrides:
visitFilein classjava.nio.file.SimpleFileVisitor<java.nio.file.Path>- Throws:
java.io.IOException
-
visitFileFailed
public java.nio.file.FileVisitResult visitFileFailed(java.nio.file.Path file, java.io.IOException ioException) throws java.io.IOException- Specified by:
visitFileFailedin interfacejava.nio.file.FileVisitor<java.nio.file.Path>- Overrides:
visitFileFailedin classjava.nio.file.SimpleFileVisitor<java.nio.file.Path>- Throws:
java.io.IOException
-
delete
protected void delete(java.nio.file.Path file) throws java.io.IOExceptionDeletes the specified file.- Parameters:
file- the file to delete- Throws:
java.io.IOException- if a problem occurred deleting the file
-
isTestMode
public boolean isTestMode()
Returnstrueif files are not deleted even when all conditions accept a path,falseotherwise.- Returns:
trueif files are not deleted even when all conditions accept a path,falseotherwise
-
-