This project has retired. For details please refer to its Attic page.
AutoClosingIterator (Apache Crunch 0.9.0 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 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 © 2014 The Apache Software Foundation. All Rights Reserved.