This project has retired. For details please refer to its Attic page.
AutoClosingIterator (Apache Crunch 0.3.0-incubating API)

org.apache.crunch.io.impl
Class AutoClosingIterator<T>

java.lang.Object
  extended by com.google.common.collect.UnmodifiableIterator<T>
      extended by org.apache.crunch.io.impl.AutoClosingIterator<T>
All Implemented Interfaces:
Closeable, Iterator<T>

public class AutoClosingIterator<T>
extends com.google.common.collect.UnmodifiableIterator<T>
implements Iterator<T>, Closeable

Closes the wrapped Closeable when hasNext() returns false. As long a client loops through to completion (doesn't abort early due to an exception, short circuit, etc.) resources will be closed automatically.


Constructor Summary
AutoClosingIterator(Closeable closeable, Iterator<T> iter)
           
 
Method Summary
 void close()
           
 boolean hasNext()
           
 T next()
           
 
Methods inherited from class com.google.common.collect.UnmodifiableIterator
remove
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Iterator
remove
 

Constructor Detail

AutoClosingIterator

public AutoClosingIterator(Closeable closeable,
                           Iterator<T> iter)
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<T>

next

public T next()
Specified by:
next in interface Iterator<T>

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.