edu.iris.Fissures.seed.director
Class ReadBuffer

java.lang.Object
  extended by edu.iris.Fissures.seed.director.ReadBuffer

public class ReadBuffer
extends java.lang.Object

This class is a generic file read buffer that takes on the task of keeping a full byte array buffer available for Director classes to extract from.
This class can be used for any file format.
This class does not perform the tasks of determining record lengths or verification of the records it is reading in.
What it does is fill the buffer to its initialized capacity, which should be the maximum possible logical record length, or even the maximum possible physical record length of the volume.
Outside routines will examine the buffer and decide where to stop reading, whether it is at the edge of a logical record, or otherwise.
When a portion of the buffer has been read, this class can be told to shift the data by that amount to allow space for more data to be read in.
A good recommendation is to make the buffer size two times the expected logical record length.

Version:
11/14/2002
Author:
Robert Casey, IRIS DMC

Field Summary
protected  byte[] buffer
          Buffer holding the data from the input stream
static int defaultBufSize
          Default buffer capacity (32768)
 
Constructor Summary
ReadBuffer()
          A default buffer size will be used here (defaultBufSize).
ReadBuffer(int bufSize)
          Create a ReadBuffer with the specified buffer size.
 
Method Summary
 int bufSize()
          Return the size of the buffer.
 void fill(java.io.DataInputStream inStream)
          Fill the empty space of the buffer with new data
 int length()
          Return the current length of data present.
 boolean reachedEOF()
          Return true if the input stream is at EOF
 void shift(int amount)
          Left-shift the data in the buffer by a certain number of bytes to make room for new incoming data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected byte[] buffer
Buffer holding the data from the input stream


defaultBufSize

public static final int defaultBufSize
Default buffer capacity (32768)

See Also:
Constant Field Values
Constructor Detail

ReadBuffer

public ReadBuffer(int bufSize)
Create a ReadBuffer with the specified buffer size.

Parameters:
bufSize - buffer size in bytes

ReadBuffer

public ReadBuffer()
A default buffer size will be used here (defaultBufSize).

Method Detail

length

public int length()
Return the current length of data present.

Returns:
length of data currently in buffer

bufSize

public int bufSize()
Return the size of the buffer.

Returns:
size of the buffer in bytes

fill

public void fill(java.io.DataInputStream inStream)
          throws SeedException,
                 java.io.IOException
Fill the empty space of the buffer with new data

Parameters:
inStream - input stream to fill the buffer with
Throws:
SeedInputException - if bufSize is less than dataLength
java.io.IOException
SeedException

shift

public void shift(int amount)
Left-shift the data in the buffer by a certain number of bytes to make room for new incoming data

Parameters:
amount - number of bytes to shift the buffer by

reachedEOF

public boolean reachedEOF()
Return true if the input stream is at EOF

Returns:
true if the input stream is at EOF