com.google.enterprise.adaptor.prebuilt
Class RecursiveFileIterator

java.lang.Object
  extended by com.google.enterprise.adaptor.prebuilt.RecursiveFileIterator
All Implemented Interfaces:
Iterable<File>, Iterator<File>

public class RecursiveFileIterator
extends Object
implements Iterator<File>, Iterable<File>

Iterate over all files within a folder, including files in subdirectories.


Nested Class Summary
 class RecursiveFileIterator.WrappedIOException
          Allows throwing IOExceptions and allowing the caller to unpack and rethrow them with certainty.
 
Constructor Summary
RecursiveFileIterator(File rootFile)
           
 
Method Summary
 boolean hasNext()
          Returns true if the iteration has more elements.
 Iterator<File> iterator()
          Returns this to allow using with foreach loops.
 File next()
          Returns the next file in the iteratior.
 void remove()
          Unsupported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecursiveFileIterator

public RecursiveFileIterator(File rootFile)
Parameters:
rootFile - directory to recursively list contents
Method Detail

iterator

public Iterator<File> iterator()
Returns this to allow using with foreach loops.

Specified by:
iterator in interface Iterable<File>

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. Even if this method throws a WrappedIOException, the iterator can continue to list files. However, each exception would note a directory that could not be descended into.

Specified by:
hasNext in interface Iterator<File>
Throws:
RecursiveFileIterator.WrappedIOException - if there was an IOException

next

public File next()
Returns the next file in the iteratior. Even if this method throws a WrappedIOException, the iterator can continue to list files. However, each exception would note a directory that could not be descended into.

Specified by:
next in interface Iterator<File>
Throws:
RecursiveFileIterator.WrappedIOException - if there was an IOException

remove

public void remove()
Unsupported.

Specified by:
remove in interface Iterator<File>
Throws:
UnsupportedOperationException - always