Package manifold.io
Class FileTreeWalk
- java.lang.Object
-
- manifold.io.FileTreeWalk
-
public class FileTreeWalk extends Object implements Iterable<File>
This class is intended to implement different file traversal methods. It allows to iterate through all files inside a given directory.Use
File.walk,File.walkTopDownorFile.walkBottomUpextension methods to instantiate aFileTreeWalkinstance.If the file path given is just a file, walker iterates only it. If the file path given does not exist, walker iterates nothing, i.e., it's equivalent to an empty sequence.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileTreeWalk.FileWalkDirectionAn enumeration to describe possible walk directions.
-
Constructor Summary
Constructors Constructor Description FileTreeWalk(File start)FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction)FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction, Function<File,Boolean> onEnter, Consumer<File> onLeave, BiConsumer<File,IOException> onFail, int maxDepth)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterator<File>iterator()Returns an iterator walking through files.FileTreeWalkmaxDepth(int depth)Sets the maximum [depth] of a directory tree to traverse.FileTreeWalkonEnter(Function<File,Boolean> function)Sets a predicate [function], that is called on any entered directory before its files are visited and before it is visited itself.FileTreeWalkonFail(BiConsumer<File,IOException> function)Set a callback [function], that is called on a directory when it's impossible to get its file list.FileTreeWalkonLeave(Consumer<File> function)Sets a callback [function], that is called on any left directory after its files are visited and after it is visited itself.-
Methods inherited from class java.lang.Object
clone, emptyArray, equals, finalize, getClass, hashCode, jailbreak, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
count, count, distinctBy, distinctList, filterIndexedTo, filterIndexedToList, filterNotTo, filterNotToList, filterTo, filterToList, first, first, firstOrNull, firstOrNull, flatMap, flatMapTo, fold, forEach, forEachIndexed, indexOfFirst, indexOfLast, intersect, joinTo, joinToString, last, last, lastOrNull, lastOrNull, mapIndexed, mapIndexedNotNull, mapIndexedNotNullTo, mapIndexedNotNullToList, mapIndexedTo, mapIndexedToList, mapNotNull, mapNotNullTo, mapNotNullToList, mapTo, mapToList, maxWith, minWith, partition, reversed, single, single, singleOrNull, singleOrNull, spliterator, subList, subList, subtract, toList, toSet, union
-
-
-
-
Constructor Detail
-
FileTreeWalk
public FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction, Function<File,Boolean> onEnter, Consumer<File> onLeave, BiConsumer<File,IOException> onFail, int maxDepth)
-
FileTreeWalk
public FileTreeWalk(File start, FileTreeWalk.FileWalkDirection direction)
-
FileTreeWalk
public FileTreeWalk(File start)
-
-
Method Detail
-
onEnter
public FileTreeWalk onEnter(Function<File,Boolean> function)
Sets a predicate [function], that is called on any entered directory before its files are visited and before it is visited itself.If the [function] returns `false` the directory is not entered and neither it nor its files are visited.
-
onLeave
public FileTreeWalk onLeave(Consumer<File> function)
Sets a callback [function], that is called on any left directory after its files are visited and after it is visited itself.
-
onFail
public FileTreeWalk onFail(BiConsumer<File,IOException> function)
Set a callback [function], that is called on a directory when it's impossible to get its file list.[onEnter] and [onLeave] callback functions are called even in this case.
-
maxDepth
public FileTreeWalk maxDepth(int depth)
Sets the maximum [depth] of a directory tree to traverse. By default there is no limit.The value must be positive and [Int.MAX_VALUE] is used to specify an unlimited depth.
With a value of 1, walker visits only the origin directory and all its immediate children, with a value of 2 also grandchildren, etc.
-
-