Class 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.
    • 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()
      Returns true 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)  
      • Methods inherited from class java.nio.file.SimpleFileVisitor

        postVisitDirectory, preVisitDirectory
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 paths
        pathConditions - objects that need to confirm whether a file can be deleted
        testMode - 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 interface java.nio.file.FileVisitor<java.nio.file.Path>
        Overrides:
        visitFile in class java.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 interface java.nio.file.FileVisitor<java.nio.file.Path>
        Overrides:
        visitFileFailed in class java.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()
        Returns true 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