public class ByteArrayReader extends java.lang.Object implements BufferReader
setMotorolaByteOrder(boolean)
.Constructor and Description |
---|
ByteArrayReader(byte[] buffer) |
Modifier and Type | Method and Description |
---|---|
byte[] |
getBytes(int index,
int count) |
double |
getDouble64(int index) |
float |
getFloat32(int index) |
short |
getInt16(int index)
Returns a signed 16-bit int calculated from two bytes of data at the specified index (MSB, LSB).
|
int |
getInt32(int index)
Returns a signed 32-bit integer from four bytes of data at the specified index the buffer.
|
long |
getInt64(int index)
Get a signed 64-bit integer from the buffer.
|
byte |
getInt8(int index)
Returns a signed 8-bit int calculated from one byte of data at the specified index.
|
long |
getLength()
Returns the length of the buffer.
|
java.lang.String |
getNullTerminatedString(int index,
int maxLengthBytes)
Creates a String from the _data buffer starting at the specified index,
and ending where
byte=='\0' or where length==maxLength . |
float |
getS15Fixed16(int index) |
java.lang.String |
getString(int index,
int bytesRequested) |
java.lang.String |
getString(int index,
int bytesRequested,
java.lang.String charset) |
int |
getUInt16(int index)
Returns an unsigned 16-bit int calculated from two bytes of data at the specified index.
|
long |
getUInt32(int index)
Get a 32-bit unsigned integer from the buffer, returning it as a long.
|
short |
getUInt8(int index)
Returns an unsigned 8-bit int calculated from one byte of data at the specified index.
|
boolean |
isMotorolaByteOrder()
Gets the endianness of this reader.
|
void |
setMotorolaByteOrder(boolean motorolaByteOrder)
Sets the endianness of this reader.
|
public long getLength()
BufferReader
getLength
in interface BufferReader
public void setMotorolaByteOrder(boolean motorolaByteOrder)
BufferReader
true
for Motorola (or big) endiannessfalse
for Intel (or little) endiannesssetMotorolaByteOrder
in interface BufferReader
motorolaByteOrder
- true
for motorola/big endian, false
for intel/little endianpublic boolean isMotorolaByteOrder()
BufferReader
true
for Motorola (or big) endiannessfalse
for Intel (or little) endiannessisMotorolaByteOrder
in interface BufferReader
public short getUInt8(int index) throws BufferBoundsException
BufferReader
getUInt8
in interface BufferReader
index
- position within the data buffer to read byteBufferBoundsException
- the buffer does not contain enough bytes to service the request, or index is negativepublic byte getInt8(int index) throws BufferBoundsException
BufferReader
getInt8
in interface BufferReader
index
- position within the data buffer to read byteBufferBoundsException
- the buffer does not contain enough bytes to service the request, or index is negativepublic int getUInt16(int index) throws BufferBoundsException
BufferReader
getUInt16
in interface BufferReader
index
- position within the data buffer to read first byteBufferBoundsException
- the buffer does not contain enough bytes to service the request, or index is negativepublic short getInt16(int index) throws BufferBoundsException
BufferReader
getInt16
in interface BufferReader
index
- position within the data buffer to read first byteBufferBoundsException
- the buffer does not contain enough bytes to service the request, or index is negativepublic long getUInt32(int index) throws BufferBoundsException
BufferReader
getUInt32
in interface BufferReader
index
- position within the data buffer to read first byteBufferBoundsException
- the buffer does not contain enough bytes to service the request, or index is negativepublic int getInt32(int index) throws BufferBoundsException
BufferReader
getInt32
in interface BufferReader
index
- position within the data buffer to read first byteBufferBoundsException
- the buffer does not contain enough bytes to service the request, or index is negativepublic long getInt64(int index) throws BufferBoundsException
BufferReader
getInt64
in interface BufferReader
index
- position within the data buffer to read first byteBufferBoundsException
- the buffer does not contain enough bytes to service the request, or index is negativepublic float getS15Fixed16(int index) throws BufferBoundsException
getS15Fixed16
in interface BufferReader
BufferBoundsException
public float getFloat32(int index) throws BufferBoundsException
getFloat32
in interface BufferReader
BufferBoundsException
public double getDouble64(int index) throws BufferBoundsException
getDouble64
in interface BufferReader
BufferBoundsException
public byte[] getBytes(int index, int count) throws BufferBoundsException
getBytes
in interface BufferReader
BufferBoundsException
public java.lang.String getString(int index, int bytesRequested) throws BufferBoundsException
getString
in interface BufferReader
BufferBoundsException
public java.lang.String getString(int index, int bytesRequested, java.lang.String charset) throws BufferBoundsException
getString
in interface BufferReader
BufferBoundsException
public java.lang.String getNullTerminatedString(int index, int maxLengthBytes) throws BufferBoundsException
BufferReader
byte=='\0'
or where length==maxLength
.getNullTerminatedString
in interface BufferReader
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.BufferBoundsException
- The buffer does not contain enough bytes to satisfy this request.Copyright © 2002-2013 Drew Noakes. All Rights Reserved.