org.openstreetmap.osmosis.core.store
Class RandomAccessObjectStoreReader<T>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.store.RandomAccessObjectStoreReader<T>
Type Parameters:
T - The object type being stored.
All Implemented Interfaces:
Releasable

public class RandomAccessObjectStoreReader<T>
extends java.lang.Object
implements Releasable

Provides read-only access to a random access object store. Each thread accessing the object store must create its own reader. The reader maintains all references to heavyweight resources such as file handles used to access the store eliminating the need for objects such as object iterators to be cleaned up explicitly.

Author:
Brett Henderson

Constructor Summary
RandomAccessObjectStoreReader(BufferedRandomAccessFileInputStream randomFile, ObjectReader objectReader)
          Creates a new instance.
 
Method Summary
 T get(long offset)
          Reads the object at the specified file offset.
 java.util.Iterator<T> iterate()
          Iterates over the entire stream of data.
 java.util.Iterator<T> iterate(long offset)
          Iterates over the entire stream of data.
 long length()
          Returns the length of data.
 long position()
          Returns the current read position.
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessObjectStoreReader

public RandomAccessObjectStoreReader(BufferedRandomAccessFileInputStream randomFile,
                                     ObjectReader objectReader)
Creates a new instance.

Parameters:
randomFile - A read-only random access file opened on the store file.
objectReader - The reader containing the objects to be deserialized.
Method Detail

get

public T get(long offset)
Reads the object at the specified file offset.

Parameters:
offset - The file offset to read an object from.
Returns:
The requested object.

length

public long length()
Returns the length of data.

Returns:
The data length in bytes.

position

public long position()
Returns the current read position.

Returns:
The current offset offset in bytes.

iterate

public java.util.Iterator<T> iterate(long offset)
Iterates over the entire stream of data.

Parameters:
offset - The location in the storage file to begin reading.
Returns:
An iterator for reading objects from the data store. This iterator must be released after use.

iterate

public java.util.Iterator<T> iterate()
Iterates over the entire stream of data.

Returns:
An iterator for reading objects from the data store. This iterator must be released after use.

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