org.openstreetmap.osmosis.core.store
Class BufferedRandomAccessFileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.openstreetmap.osmosis.core.store.BufferedRandomAccessFileInputStream
All Implemented Interfaces:
java.io.Closeable

public class BufferedRandomAccessFileInputStream
extends java.io.InputStream

Wraps a random access file adding buffered input stream capabilities. This allows a file to be randomly accessed while providing performance improvements over the non-buffered random access file implementation.

Author:
Brett Henderson

Constructor Summary
BufferedRandomAccessFileInputStream(java.io.File file)
          Creates a new instance.
BufferedRandomAccessFileInputStream(java.io.File file, int bufferCount, int initialBufferSize, int maxBufferSize, float bufferIncreaseFactor)
          Creates a new instance.
 
Method Summary
 void close()
          
 long length()
          Returns the length of the data file.
 long position()
          Returns the current read position in the data file.
 int read()
          
 int read(byte[] b)
          
 int read(byte[] b, int off, int len)
          
 void seek(long pos)
          Seeks to the specified position in the file.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedRandomAccessFileInputStream

public BufferedRandomAccessFileInputStream(java.io.File file)
                                    throws java.io.FileNotFoundException
Creates a new instance.

Parameters:
file - The file to be read.
Throws:
java.io.FileNotFoundException - if the file cannot be opened.

BufferedRandomAccessFileInputStream

public BufferedRandomAccessFileInputStream(java.io.File file,
                                           int bufferCount,
                                           int initialBufferSize,
                                           int maxBufferSize,
                                           float bufferIncreaseFactor)
                                    throws java.io.FileNotFoundException
Creates a new instance.

Parameters:
file - The file to be read.
bufferCount - The number of buffers to use. Use of multiple buffers allows some random seeks to occur without losing existing buffered data that might be returned to.
initialBufferSize - After a seek, this is the number of bytes that will be initially read.
maxBufferSize - This is the maximum number of bytes that will ever be read from the underlying file at a time.
bufferIncreaseFactor - During sequential reads, if the buffer is exhausted the next read will be longer than the previous read according to this factor. A value of 1 means the buffer never gets larger. The buffer will never get larger than maxBufferSize.
Throws:
java.io.FileNotFoundException - if the file cannot be opened.
Method Detail

read

public int read()
         throws java.io.IOException

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

seek

public void seek(long pos)
          throws java.io.IOException
Seeks to the specified position in the file.

Parameters:
pos - The position within the file to seek to.
Throws:
java.io.IOException - if an error occurs during seeking.

length

public long length()
            throws java.io.IOException
Returns the length of the data file.

Returns:
The file length in bytes.
Throws:
java.io.IOException - if an error occurs during the length operation.

position

public long position()
              throws java.io.IOException
Returns the current read position in the data file.

Returns:
The current file offset in bytes.
Throws:
java.io.IOException - if an error occurs during the position operation.

close

public void close()
           throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException