org.apache.tools.ant.taskdefs.optional.depend

## Class DirectoryIterator

- java.lang.Object
- - org.apache.tools.ant.taskdefs.optional.depend.DirectoryIterator

All Implemented Interfaces:
  java.lang.Iterable<ClassFile>, ClassFileIterator

    public class DirectoryIterator
    extends java.lang.Object
    implements ClassFileIterator

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.

### Constructor Summary

Constructors
Constructor and Description
`DirectoryIterator(java.io.File rootDirectory, boolean changeInto)` Creates a directory iterator.

### Method Summary

All Methods Instance Methods Concrete Methods
`ClassFile` `getNextClassFile()` Template method to allow subclasses to supply elements for the iteration.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.tools.ant.taskdefs.optional.depend.ClassFileIterator

`iterator`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Constructor Detail

#### DirectoryIterator

    public DirectoryIterator(java.io.File rootDirectory,
                             boolean changeInto)
                      throws java.io.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` - the root if the directory namespace which is to be iterated over
  `changeInto` - if true then the returned entries will be relative to the rootDirectory and not the current directory.
Throws:
  `java.io.IOException` - if there is a problem reading the directory information.

### Method Detail

#### getNextClassFile

    public ClassFile 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.

Specified by:
  `getNextClassFile` in interface `ClassFileIterator`
Returns:
  the next ClassFile in the iteration.