org.openstreetmap.osmosis.core.store
Class PersistentIterator<T extends Storeable>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.store.PersistentIterator<T>
Type Parameters:
T - The type of entity to retrieved.
All Implemented Interfaces:
java.util.Iterator<T>, Releasable, ReleasableIterator<T>

public class PersistentIterator<T extends Storeable>
extends java.lang.Object
implements ReleasableIterator<T>

Wraps an underlying iterator implementation so that all data is read from the underlying reader and written to a temporary file before being returned. This allows underlying resources such as database connections to be closed sooner than otherwise possible. This object will own the wrapped source iterator and release it along with all other resources.

Author:
Brett Henderson

Constructor Summary
PersistentIterator(ObjectSerializationFactory serializationFactory, ReleasableIterator<T> sourceIterator, java.lang.String storageFilePrefix, boolean useCompression)
          Creates a new instance.
 
Method Summary
 boolean hasNext()
          
 T next()
          
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 void remove()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistentIterator

public PersistentIterator(ObjectSerializationFactory serializationFactory,
                          ReleasableIterator<T> sourceIterator,
                          java.lang.String storageFilePrefix,
                          boolean useCompression)
Creates a new instance.

Parameters:
serializationFactory - The factory defining the object serialisation implementation.
sourceIterator - The source of data.
storageFilePrefix - The prefix of the storage file.
useCompression - If true, the storage file will be compressed.
Method Detail

hasNext

public boolean hasNext()

Specified by:
hasNext in interface java.util.Iterator<T extends Storeable>

next

public T next()

Specified by:
next in interface java.util.Iterator<T extends Storeable>

release

public void release()
Performs resource cleanup tasks such as closing files, or database connections. This must be called after all processing is complete and may be called multiple times. Implementations must call release on any nested Releasable objects. It should be called within a finally block to ensure it is called in exception scenarios.

Specified by:
release in interface Releasable

remove

public void remove()

Specified by:
remove in interface java.util.Iterator<T extends Storeable>