public class RandomAccessStreamReader extends RandomAccessReader
Modifier and Type | Field and Description |
---|---|
private int |
_chunkLength |
private java.util.ArrayList<byte[]> |
_chunks |
private boolean |
_isStreamFinished |
private java.io.InputStream |
_stream |
private long |
_streamLength |
static int |
DEFAULT_CHUNK_LENGTH |
Constructor and Description |
---|
RandomAccessStreamReader(java.io.InputStream stream) |
RandomAccessStreamReader(java.io.InputStream stream,
int chunkLength) |
RandomAccessStreamReader(java.io.InputStream stream,
int chunkLength,
long streamLength) |
Modifier and Type | Method and Description |
---|---|
byte |
getByte(int index)
Gets the byte value at the specified byte
index . |
byte[] |
getBytes(int index,
int count)
Returns the required number of bytes from the specified index from the underlying source.
|
long |
getLength()
Reads to the end of the stream, in order to determine the total number of bytes.
|
protected boolean |
isValidIndex(int index,
int bytesRequested) |
int |
toUnshiftedOffset(int localOffset) |
protected void |
validateIndex(int index,
int bytesRequested)
Ensures that the buffered bytes extend to cover the specified index.
|
getBit, getDouble64, getFloat32, getInt16, getInt24, getInt32, getInt64, getInt8, getNullTerminatedBytes, getNullTerminatedString, getNullTerminatedStringValue, getS15Fixed16, getString, getString, getStringValue, getUInt16, getUInt32, getUInt8, isMotorolaByteOrder, setMotorolaByteOrder
public static final int DEFAULT_CHUNK_LENGTH
private final java.io.InputStream _stream
private final int _chunkLength
private final java.util.ArrayList<byte[]> _chunks
private boolean _isStreamFinished
private long _streamLength
public RandomAccessStreamReader(java.io.InputStream stream)
public RandomAccessStreamReader(java.io.InputStream stream, int chunkLength)
public RandomAccessStreamReader(java.io.InputStream stream, int chunkLength, long streamLength)
public long getLength() throws java.io.IOException
RandomAccessReader
.getLength
in class RandomAccessReader
java.io.IOException
protected void validateIndex(int index, int bytesRequested) throws java.io.IOException
If the stream ends before the point is reached, a BufferBoundsException
is raised.
validateIndex
in class RandomAccessReader
index
- the index from which the required bytes startbytesRequested
- the number of bytes which are requiredBufferBoundsException
- if the stream ends before the required number of bytes are acquiredjava.io.IOException
- if the stream ends before the required number of bytes are acquiredprotected boolean isValidIndex(int index, int bytesRequested) throws java.io.IOException
isValidIndex
in class RandomAccessReader
java.io.IOException
public int toUnshiftedOffset(int localOffset)
toUnshiftedOffset
in class RandomAccessReader
public byte getByte(int index) throws java.io.IOException
RandomAccessReader
index
.
Implementations should not perform any bounds checking in this method. That should be performed
in validateIndex
and isValidIndex
.
getByte
in class RandomAccessReader
index
- The index from which to read the byteBufferBoundsException
- if the requested byte is beyond the end of the underlying data sourcejava.io.IOException
- if the byte is unable to be readpublic byte[] getBytes(int index, int count) throws java.io.IOException
RandomAccessReader
getBytes
in class RandomAccessReader
index
- The index from which the bytes begins in the underlying sourcecount
- The number of bytes to be returnedBufferBoundsException
- if the requested bytes extend beyond the end of the underlying data sourcejava.io.IOException
- if the byte is unable to be read