Class RandomAccessReader
- java.lang.Object
 - 
- com.drew.lang.RandomAccessReader
 
 
- 
- Direct Known Subclasses:
 ByteArrayReader,RandomAccessFileReader,RandomAccessStreamReader
public abstract class RandomAccessReader extends java.lang.ObjectBase class for random access data reading operations of common data types.By default, the reader operates with Motorola byte order (big endianness). This can be changed by calling
setMotorolaByteOrder(boolean).Concrete implementations include:
 
- 
- 
Constructor Summary
Constructors Constructor Description RandomAccessReader() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleangetBit(int index)Gets whether a bit at a specific index is set or not.abstract bytegetByte(int index)Gets the byte value at the specified byteindex.abstract byte[]getBytes(int index, int count)Returns the required number of bytes from the specified index from the underlying source.doublegetDouble64(int index)floatgetFloat32(int index)shortgetInt16(int index)Returns a signed 16-bit int calculated from two bytes of data at the specified index (MSB, LSB).intgetInt24(int index)Get a 24-bit unsigned integer from the buffer, returning it as an int.intgetInt32(int index)Returns a signed 32-bit integer from four bytes of data at the specified index the buffer.longgetInt64(int index)Get a signed 64-bit integer from the buffer.bytegetInt8(int index)Returns a signed 8-bit int calculated from one byte of data at the specified index.abstract longgetLength()Returns the length of the data source in bytes.byte[]getNullTerminatedBytes(int index, int maxLengthBytes)Returns the sequence of bytes punctuated by a\0value.java.lang.StringgetNullTerminatedString(int index, int maxLengthBytes, java.nio.charset.Charset charset)Creates a String from the _data buffer starting at the specified index, and ending wherebyte=='\0'or wherelength==maxLength.StringValuegetNullTerminatedStringValue(int index, int maxLengthBytes, java.nio.charset.Charset charset)floatgetS15Fixed16(int index)Gets a s15.16 fixed point float from the buffer.java.lang.StringgetString(int index, int bytesRequested, java.lang.String charset)java.lang.StringgetString(int index, int bytesRequested, java.nio.charset.Charset charset)StringValuegetStringValue(int index, int bytesRequested, java.nio.charset.Charset charset)intgetUInt16(int index)Returns an unsigned 16-bit int calculated from two bytes of data at the specified index.longgetUInt32(int index)Get a 32-bit unsigned integer from the buffer, returning it as a long.shortgetUInt8(int index)Returns an unsigned 8-bit int calculated from one byte of data at the specified index.booleanisMotorolaByteOrder()Gets the endianness of this reader.voidsetMotorolaByteOrder(boolean motorolaByteOrder)Sets the endianness of this reader.abstract inttoUnshiftedOffset(int localOffset) 
 - 
 
- 
- 
Method Detail
- 
toUnshiftedOffset
public abstract int toUnshiftedOffset(int localOffset)
 
- 
getByte
public abstract byte getByte(int index) throws java.io.IOExceptionGets the byte value at the specified byteindex.Implementations should not perform any bounds checking in this method. That should be performed in
validateIndexandisValidIndex.- Parameters:
 index- The index from which to read the byte- Returns:
 - The read byte value
 - Throws:
 java.lang.IllegalArgumentException-indexis negativeBufferBoundsException- 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 abstract byte[] getBytes(int index, int count) throws java.io.IOExceptionReturns the required number of bytes from the specified index from the underlying source.- 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:
 java.lang.IllegalArgumentException-indexorcountare negativeBufferBoundsException- if the requested bytes extend beyond the end of the underlying data sourcejava.io.IOException- if the byte is unable to be read
 
- 
getLength
public abstract long getLength() throws java.io.IOExceptionReturns the length of the data source in bytes.This is a simple operation for implementations (such as
RandomAccessFileReaderandByteArrayReader) that have the entire data source available.Users of this method must be aware that sequentially accessed implementations such as
RandomAccessStreamReaderwill have to read and buffer the entire data source in order to determine the length.- Returns:
 - the length of the data source, in bytes.
 - Throws:
 java.io.IOException
 
- 
setMotorolaByteOrder
public void setMotorolaByteOrder(boolean motorolaByteOrder)
Sets the endianness of this reader.truefor Motorola (or big) endianness (also known as network byte order), with MSB before LSB.falsefor Intel (or little) endianness, with LSB before MSB.
- Parameters:
 motorolaByteOrder-truefor Motorola/big endian,falsefor Intel/little endian
 
- 
isMotorolaByteOrder
public boolean isMotorolaByteOrder()
Gets the endianness of this reader.truefor Motorola (or big) endianness (also known as network byte order), with MSB before LSB.falsefor Intel (or little) endianness, with LSB before MSB.
 
- 
getBit
public boolean getBit(int index) throws java.io.IOExceptionGets whether a bit at a specific index is set or not.- Parameters:
 index- the number of bits at which to test- Returns:
 - true if the bit is set, otherwise false
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getUInt8
public short getUInt8(int index) throws java.io.IOExceptionReturns an unsigned 8-bit int calculated from one byte of data at the specified index.- Parameters:
 index- position within the data buffer to read byte- Returns:
 - the 8 bit int value, between 0 and 255
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getInt8
public byte getInt8(int index) throws java.io.IOExceptionReturns a signed 8-bit int calculated from one byte of data at the specified index.- Parameters:
 index- position within the data buffer to read byte- Returns:
 - the 8 bit int value, between 0x00 and 0xFF
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getUInt16
public int getUInt16(int index) throws java.io.IOExceptionReturns an unsigned 16-bit int calculated from two bytes of data at the specified index.- Parameters:
 index- position within the data buffer to read first byte- Returns:
 - the 16 bit int value, between 0x0000 and 0xFFFF
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getInt16
public short getInt16(int index) throws java.io.IOExceptionReturns a signed 16-bit int calculated from two bytes of data at the specified index (MSB, LSB).- Parameters:
 index- position within the data buffer to read first byte- Returns:
 - the 16 bit int value, between 0x0000 and 0xFFFF
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getInt24
public int getInt24(int index) throws java.io.IOExceptionGet a 24-bit unsigned integer from the buffer, returning it as an int.- Parameters:
 index- position within the data buffer to read first byte- Returns:
 - the unsigned 24-bit int value as a long, between 0x00000000 and 0x00FFFFFF
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getUInt32
public long getUInt32(int index) throws java.io.IOExceptionGet a 32-bit unsigned integer from the buffer, returning it as a long.- Parameters:
 index- position within the data buffer to read first byte- Returns:
 - the unsigned 32-bit int value as a long, between 0x00000000 and 0xFFFFFFFF
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getInt32
public int getInt32(int index) throws java.io.IOExceptionReturns a signed 32-bit integer from four bytes of data at the specified index the buffer.- Parameters:
 index- position within the data buffer to read first byte- Returns:
 - the signed 32 bit int value, between 0x00000000 and 0xFFFFFFFF
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getInt64
public long getInt64(int index) throws java.io.IOExceptionGet a signed 64-bit integer from the buffer.- Parameters:
 index- position within the data buffer to read first byte- Returns:
 - the 64 bit int value, between 0x0000000000000000 and 0xFFFFFFFFFFFFFFFF
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getS15Fixed16
public float getS15Fixed16(int index) throws java.io.IOExceptionGets a s15.16 fixed point float from the buffer.This particular fixed point encoding has one sign bit, 15 numerator bits and 16 denominator bits.
- Returns:
 - the floating point value
 - Throws:
 java.io.IOException- the buffer does not contain enough bytes to service the request, or index is negative
 
- 
getFloat32
public float getFloat32(int index) throws java.io.IOException- Throws:
 java.io.IOException
 
- 
getDouble64
public double getDouble64(int index) throws java.io.IOException- Throws:
 java.io.IOException
 
- 
getStringValue
public StringValue getStringValue(int index, int bytesRequested, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
getString
public java.lang.String getString(int index, int bytesRequested, java.nio.charset.Charset charset) throws java.io.IOException- Throws:
 java.io.IOException
 
- 
getString
public java.lang.String getString(int index, int bytesRequested, java.lang.String charset) throws java.io.IOException- Throws:
 java.io.IOException
 
- 
getNullTerminatedString
public java.lang.String getNullTerminatedString(int index, int maxLengthBytes, java.nio.charset.Charset charset) throws java.io.IOExceptionCreates a String from the _data buffer starting at the specified index, and ending wherebyte=='\0'or wherelength==maxLength.- Parameters:
 index- The index within the buffer at which to start reading the string.maxLengthBytes- The maximum number of bytes to read. If a zero-byte is not reached within this limit, reading will stop and the string will be truncated to this length.- Returns:
 - The read string.
 - Throws:
 java.io.IOException- The buffer does not contain enough bytes to satisfy this request.
 
- 
getNullTerminatedStringValue
public StringValue getNullTerminatedStringValue(int index, int maxLengthBytes, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
 java.io.IOException
 
- 
getNullTerminatedBytes
public byte[] getNullTerminatedBytes(int index, int maxLengthBytes) throws java.io.IOExceptionReturns the sequence of bytes punctuated by a\0value.- Parameters:
 index- The index within the buffer at which to start reading the string.maxLengthBytes- The maximum number of bytes to read. If a\0byte is not reached within this limit, the returned array will bemaxLengthByteslong.- Returns:
 - The read byte array, excluding the null terminator.
 - Throws:
 java.io.IOException- The buffer does not contain enough bytes to satisfy this request.
 
 - 
 
 -