Top Description Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional.depend

public Class DirectoryIterator

extends Object
implements ClassFileIterator
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.optional.depend.ClassFileIterator, java.lang.Iterable
Imports
java.io.File, .IOException, .InputStream, java.nio.file.Files, java.util.ArrayDeque, .Arrays, .Collections, .Deque, .Iterator, .List

An iterator which iterates through the contents of a java directory. The iterator should be created with the directory at the root of the Java namespace.

Field Summary

Modifier and TypeField and Description
private Iterator<File>
currentIterator

The current directory iterator.

private Deque<Iterator<File>>
enumStack

This is a stack of current iterators supporting the depth first traversal of the directory tree.

Constructor Summary

AccessConstructor and Description
public
DirectoryIterator(File
the root if the directory namespace which is to be iterated over
rootDirectory
,
boolean
if true then the returned entries will be relative to the rootDirectory and not the current directory.
changeInto
)

Creates a directory iterator.

Method Summary

Modifier and TypeMethod and Description
private List<File>

Returns:

a vector containing File objects for each entry in the directory.
getDirectoryEntries
(File
the directory to be scanned.
directory
)

Get a vector covering all the entries (files and subdirectories in a directory).

public ClassFile

Returns:

the next ClassFile in the iteration.
getNextClassFile
()

Implements org.apache.tools.ant.taskdefs.optional.depend.ClassFileIterator.getNextClassFile.

Template method to allow subclasses to supply elements for the iteration.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentIteratorback to summary
private Iterator<File> currentIterator

The current directory iterator. As directories encounter lower level directories, the current iterator is pushed onto the iterator stack and a new iterator over the sub directory becomes the current directory. This implements a depth first traversal of the directory namespace.

enumStackback to summary
private Deque<Iterator<File>> enumStack

This is a stack of current iterators supporting the depth first traversal of the directory tree.

Constructor Detail

DirectoryIteratorback to summary
public DirectoryIterator(File rootDirectory, boolean changeInto) throws IOException

Creates a directory iterator. The directory iterator is created to scan the root directory. If the changeInto flag is given, then the entries returned will be relative to this directory and not the current directory.

Parameters
rootDirectory:File

the root if the directory namespace which is to be iterated over

changeInto:boolean

if true then the returned entries will be relative to the rootDirectory and not the current directory.

Exceptions
IOException:
if there is a problem reading the directory information.

Method Detail

getDirectoryEntriesback to summary
private List<File> getDirectoryEntries(File directory)

Get a vector covering all the entries (files and subdirectories in a directory).

Parameters
directory:File

the directory to be scanned.

Returns:List<File>

a vector containing File objects for each entry in the directory.

getNextClassFileback to summary
public ClassFile getNextClassFile()

Implements org.apache.tools.ant.taskdefs.optional.depend.ClassFileIterator.getNextClassFile.

Template method to allow subclasses to supply elements for the iteration. The directory iterator maintains a stack of iterators covering each level in the directory hierarchy. The current iterator covers the current directory being scanned. If the next entry in that directory is a subdirectory, the current iterator is pushed onto the stack and a new iterator is created for the subdirectory. If the entry is a file, it is returned as the next element and the iterator remains valid. If there are no more entries in the current directory, the topmost iterator on the stack is popped off to become the current iterator.

Returns:ClassFile

the next ClassFile in the iteration.

Annotations
@Override