Package com.helger.io.file
Class FileSystemRecursiveIterator
java.lang.Object
com.helger.io.file.FileSystemRecursiveIterator
- All Implemented Interfaces:
com.helger.base.iface.IHasSize,com.helger.collection.base.IIterableIterator<File>,com.helger.collection.commons.ICommonsIterable<File>,com.helger.collection.commons.ICommonsIterableIterator<File>,Iterable<File>,Iterator<File>
@NotThreadSafe
public class FileSystemRecursiveIterator
extends Object
implements com.helger.collection.commons.ICommonsIterableIterator<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
Note: the order of iteration is undefined and depends on the order returned by
FileHelper.getDirectoryContent(File).- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionFileSystemRecursiveIterator(@NonNull File aBaseDir) Constructor for recursively iterating a file system directory.FileSystemRecursiveIterator(@NonNull File aBaseDir, @Nullable Predicate<File> aRecursionFilter) Constructor for recursively iterating a file system directory.FileSystemRecursiveIterator(@NonNull String sBaseDir) Constructor for recursively iterating a file system directory.FileSystemRecursiveIterator(@NonNull String sBaseDir, @Nullable Predicate<File> aRecursionFilter) Constructor for recursively iterating a file system directory. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.collection.commons.ICommonsIterable
containsAny, containsNone, containsOnly, findAll, findAllInstanceOf, findAllMapped, findAllMapped, findAllMapped, findFirst, findFirst, findFirstIndex, findFirstMapped, findFirstMapped, findLastIndex, forEachBreakable, forEachByIndex, forEachThrowing, getCount, isEmpty, sizeMethods inherited from interface com.helger.collection.commons.ICommonsIterableIterator
iterator, withFilter, withMapperMethods inherited from interface com.helger.base.iface.IHasSize
isNotEmptyMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
FileSystemRecursiveIterator
Constructor for recursively iterating a file system directory.- Parameters:
sBaseDir- The base directory to start with. May not benull.
-
FileSystemRecursiveIterator
Constructor for recursively iterating a file system directory.- Parameters:
aBaseDir- The base directory to start with. May not benull.
-
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 benull.aRecursionFilter- An optional filter that controls, into which sub-directories this iterator should descend to. May benull.
-
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 benull.aRecursionFilter- An optional filter that controls, into which sub-directories this iterator should descend to. May benull.
-
-
Method Details
-
getStartLevel
@Nonnegative public int getStartLevel()- Returns:
- The start level as determined by the base directory. Always ≥ 0.
-
getRecursionFilter
- Returns:
- The recursion filter as provided in the constructor. May be
null.
-
hasNext
public final boolean hasNext() -
recurseIntoDirectory
Override this method to manually filter the directories, which are recursed into.- Parameters:
aDirectory- The non-nulldirectory- Returns:
trueif all children of this directory should be investigated
-
next
-
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
-