public class RandomAccessFileReader extends RandomAccessReader
RandomAccessFile
, with a consistent, checked exception structure for
issues.Modifier and Type | Field and Description |
---|---|
private int |
_baseOffset |
private int |
_currentIndex |
private java.io.RandomAccessFile |
_file |
private long |
_length |
Constructor and Description |
---|
RandomAccessFileReader(java.io.RandomAccessFile file) |
RandomAccessFileReader(java.io.RandomAccessFile file,
int baseOffset) |
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()
Returns the length of the data source in bytes.
|
protected boolean |
isValidIndex(int index,
int bytesRequested) |
private void |
seek(int index) |
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
private final java.io.RandomAccessFile _file
private final long _length
private int _currentIndex
private final int _baseOffset
public RandomAccessFileReader(java.io.RandomAccessFile file) throws java.io.IOException
java.io.IOException
public RandomAccessFileReader(java.io.RandomAccessFile file, int baseOffset) throws java.io.IOException
java.io.IOException
public int toUnshiftedOffset(int localOffset)
toUnshiftedOffset
in class RandomAccessReader
public long getLength()
RandomAccessReader
This is a simple operation for implementations (such as RandomAccessFileReader
and
ByteArrayReader
) that have the entire data source available.
Users of this method must be aware that sequentially accessed implementations such as
RandomAccessStreamReader
will have to read and buffer the entire data source in
order to determine the length.
getLength
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 readprivate void seek(int index) throws java.io.IOException
java.io.IOException
protected boolean isValidIndex(int index, int bytesRequested) throws java.io.IOException
isValidIndex
in class RandomAccessReader
java.io.IOException
protected void validateIndex(int index, int bytesRequested) throws java.io.IOException
RandomAccessReader
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 requiredjava.io.IOException
- if the stream ends before the required number of bytes are acquired