jut.io
Class DirectoryTree

java.lang.Object
  extended by jut.io.DirectoryTree
All Implemented Interfaces:
Iterable<File>

public class DirectoryTree
extends Object
implements Iterable<File>

Iterable recursively iterating through the files of a directory tree. iteration is done breadth first.


Nested Class Summary
static class DirectoryTree.DirFilter
          directory listing filter. this base filter class just returns all children of a directory.
 
Constructor Summary
DirectoryTree(File root)
          create an Iterable recursively iterating through the files of a directory tree. the Iterators of this Iterable are not thread-safe.
DirectoryTree(File root, boolean onlyEmptyDirs)
          create an Iterable recursively iterating through all files of a directory tree passing the filter provided. the Iterators of this Iterable are not thread-safe.
DirectoryTree(File root, ParamCallable<List<File>,File> filter)
          create an Iterable recursively iterating through all files of a directory tree passing the filter provided. the Iterators of this Iterable are not thread-safe.
DirectoryTree(File root, ParamCallable<List<File>,File> filter, boolean onlyEmptyDirs)
          create an Iterable recursively iterating through all files of a directory tree passing the filter provided. the Iterators of this Iterable are not thread-safe.
 
Method Summary
 Iterator<File> iterator()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectoryTree

public DirectoryTree(File root)
              throws IllegalArgumentException
create an Iterable recursively iterating through the files of a directory tree. the Iterators of this Iterable are not thread-safe.

Parameters:
root - - the root directory of the file tree to iterate through.
Throws:
IllegalArgumentException - if the root file is not a directory.

DirectoryTree

public DirectoryTree(File root,
                     ParamCallable<List<File>,File> filter)
              throws IllegalArgumentException
create an Iterable recursively iterating through all files of a directory tree passing the filter provided. the Iterators of this Iterable are not thread-safe.

Parameters:
root - - the root directory of the file tree to iterate through.
filter - - a filter called for each directory encountered. the filter must return all directories and files contained that pass this filter stage. note that directories returned will also be fed into the filter to get their contents as soon as they are requested by the next() method. null can be set for the pass-all filter. the filter's Iterator will be used internally. custom filters should either subclass DirectoryTree.DirFilter and call the DirectoryTree.DirFilter.call(File) method to get the initial list of files to filter or use Files.listFiles(File). that way, directory listing can be adapted globally as described in Files.listFiles(File) e.g. for implementing a a file access speed limit.
Throws:
IllegalArgumentException - if the root file is not a directory.

DirectoryTree

public DirectoryTree(File root,
                     boolean onlyEmptyDirs)
              throws IllegalArgumentException
create an Iterable recursively iterating through all files of a directory tree passing the filter provided. the Iterators of this Iterable are not thread-safe.

Parameters:
root - - the root directory of the file tree to iterate through.
onlyEmptyDirs - - false if all directories are to be returned, true if only empty directories (i.e. directories without content after filtering) are to be returned.
Throws:
IllegalArgumentException - if the root file is not a directory.

DirectoryTree

public DirectoryTree(File root,
                     ParamCallable<List<File>,File> filter,
                     boolean onlyEmptyDirs)
              throws IllegalArgumentException
create an Iterable recursively iterating through all files of a directory tree passing the filter provided. the Iterators of this Iterable are not thread-safe.

Parameters:
root - - the root directory of the file tree to iterate through.
filter - - a filter called for each directory encountered. the filter must return all directories and files contained that pass this filter stage. note that directories returned will also be fed into the filter to get their contents as soon as they are requested by the next() method. null can be set for the pass-all filter. the filter's Iterator will be used internally. custom filters should either subclass DirectoryTree.DirFilter and call the DirectoryTree.DirFilter.call(File) method to get the initial list of files to filter or use Files.listFiles(File). that way, directory listing can be adapted globally as described in Files.listFiles(File) e.g. for implementing a a file access speed limit.
onlyEmptyDirs - - false if all directories are to be returned, true if only empty directories (i.e. directories without content after filtering) are to be returned.
Throws:
IllegalArgumentException - if the root file is not a directory.
Method Detail

iterator

public Iterator<File> iterator()

Specified by:
iterator in interface Iterable<File>