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.Path
basePath
private static Logger
LOGGER
private java.util.List<? extends PathCondition>
pathConditions
private boolean
testMode
-
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 void
delete(java.nio.file.Path file)
Deletes the specified file.boolean
isTestMode()
Returnstrue
if files are not deleted even when all conditions accept a path,false
otherwise.java.nio.file.FileVisitResult
visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs)
java.nio.file.FileVisitResult
visitFileFailed(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:
visitFile
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Overrides:
visitFile
in 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:
visitFileFailed
in interfacejava.nio.file.FileVisitor<java.nio.file.Path>
- Overrides:
visitFileFailed
in classjava.nio.file.SimpleFileVisitor<java.nio.file.Path>
- Throws:
java.io.IOException
-
delete
protected void delete(java.nio.file.Path file) throws java.io.IOException
Deletes the specified file.- Parameters:
file
- the file to delete- Throws:
java.io.IOException
- if a problem occurred deleting the file
-
isTestMode
public boolean isTestMode()
Returnstrue
if files are not deleted even when all conditions accept a path,false
otherwise.- Returns:
true
if files are not deleted even when all conditions accept a path,false
otherwise
-
-