Package com.drew.lang
Class ByteArrayReader
- java.lang.Object
-
- com.drew.lang.RandomAccessReader
-
- com.drew.lang.ByteArrayReader
-
public class ByteArrayReader extends RandomAccessReader
Provides methods to read specific values from a byte array, with a consistent, checked exception structure for issues.By default, the reader operates with Motorola byte order (big endianness). This can be changed by calling
setMotorolaByteOrder(boolean)
.
-
-
Constructor Summary
Constructors Constructor Description ByteArrayReader(byte[] buffer)
ByteArrayReader(byte[] buffer, int baseOffset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte
getByte(int index)
Gets the byte value at the specified byteindex
.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.int
toUnshiftedOffset(int localOffset)
-
Methods inherited from class com.drew.lang.RandomAccessReader
getBit, getDouble64, getFloat32, getInt16, getInt24, getInt32, getInt64, getInt8, getNullTerminatedBytes, getNullTerminatedString, getNullTerminatedStringValue, getS15Fixed16, getString, getString, getStringValue, getUInt16, getUInt32, getUInt8, isMotorolaByteOrder, setMotorolaByteOrder
-
-
-
-
Method Detail
-
toUnshiftedOffset
public int toUnshiftedOffset(int localOffset)
- Specified by:
toUnshiftedOffset
in classRandomAccessReader
-
getLength
public long getLength()
Description copied from class:RandomAccessReader
Returns the length of the data source in bytes.This is a simple operation for implementations (such as
RandomAccessFileReader
andByteArrayReader
) 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.- Specified by:
getLength
in classRandomAccessReader
- Returns:
- the length of the data source, in bytes.
-
getByte
public byte getByte(int index) throws java.io.IOException
Description copied from class:RandomAccessReader
Gets the byte value at the specified byteindex
.Implementations should not perform any bounds checking in this method. That should be performed in
validateIndex
andisValidIndex
.- Specified by:
getByte
in classRandomAccessReader
- Parameters:
index
- The index from which to read the byte- Returns:
- The read byte value
- Throws:
BufferBoundsException
- if the requested byte is beyond the end of the underlying data sourcejava.io.IOException
- if the byte is unable to be read
-
getBytes
public byte[] getBytes(int index, int count) throws java.io.IOException
Description copied from class:RandomAccessReader
Returns the required number of bytes from the specified index from the underlying source.- Specified by:
getBytes
in classRandomAccessReader
- Parameters:
index
- The index from which the bytes begins in the underlying sourcecount
- The number of bytes to be returned- Returns:
- The requested bytes
- Throws:
BufferBoundsException
- if the requested bytes extend beyond the end of the underlying data sourcejava.io.IOException
- if the byte is unable to be read
-
-