Class FileSystemRecursiveIterator

java.lang.Object
com.helger.commons.io.file.FileSystemRecursiveIterator
All Implemented Interfaces:
ICommonsIterable<File>, IIterableIterator<File>, Iterable<File>, Iterator<File>

@NotThreadSafe public class FileSystemRecursiveIterator extends Object implements IIterableIterator<File>
Recursively iterate the content of a file system directory. This is a depth first iteration, because as soon as a directory is encountered, the children of this directory are iterated.
Note: the order of iteration is undefined and depends on the order returned by FileHelper.getDirectoryContent(File).
Author:
Philip Helger
  • Constructor Details

    • FileSystemRecursiveIterator

      public FileSystemRecursiveIterator(@Nonnull String sBaseDir)
      Constructor for recursively iterating a file system directory.
      Parameters:
      sBaseDir - The base directory to start with. May not be null.
    • FileSystemRecursiveIterator

      public FileSystemRecursiveIterator(@Nonnull File aBaseDir)
      Constructor for recursively iterating a file system directory.
      Parameters:
      aBaseDir - The base directory to start with. May not be null.
    • FileSystemRecursiveIterator

      public FileSystemRecursiveIterator(@Nonnull String sBaseDir, @Nullable Predicate<File> aRecursionFilter)
      Constructor for recursively iterating a file system directory.
      Parameters:
      sBaseDir - The base directory to start with. May not be null.
      aRecursionFilter - An optional filter that controls, into which sub-directories this iterator should descend to. May be null.
    • FileSystemRecursiveIterator

      public FileSystemRecursiveIterator(@Nonnull File aBaseDir, @Nullable Predicate<File> aRecursionFilter)
      Constructor for recursively iterating a file system directory.
      Parameters:
      aBaseDir - The base directory to start with. May not be null.
      aRecursionFilter - An optional filter that controls, into which sub-directories this iterator should descend to. May be null.
  • Method Details

    • getStartLevel

      @Nonnegative public int getStartLevel()
    • getRecursionFilter

      @Nullable public Predicate<File> getRecursionFilter()
    • hasNext

      public final boolean hasNext()
      Specified by:
      hasNext in interface Iterator<File>
    • recurseIntoDirectory

      @OverrideOnDemand protected boolean recurseIntoDirectory(@Nonnull File aDirectory)
      Override this method to manually filter the directories, which are recursed into.
      Parameters:
      aDirectory - The non-null directory
      Returns:
      true if all children of this directory should be investigated
    • next

      @Nonnull public final File next()
      Specified by:
      next in interface Iterator<File>
    • getLevel

      @Nonnegative public final int getLevel()
      Returns:
      The nesting level of the last file retrieved by next(). Always ≥ 0. The starting directory has level 0.
    • toString

      public String toString()
      Overrides:
      toString in class Object