public class ByteArrayReader extends 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.
|
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) |
String |
getString(int index,
int bytesRequested) |
String |
getString(int index,
int bytesRequested,
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()
BufferReadergetLength in interface BufferReaderpublic void setMotorolaByteOrder(boolean motorolaByteOrder)
BufferReadertrue for Motorola (or big) endiannessfalse for Intel (or little) endiannesssetMotorolaByteOrder in interface BufferReadermotorolaByteOrder - true for motorola/big endian, false for intel/little endianpublic boolean isMotorolaByteOrder()
BufferReadertrue for Motorola (or big) endiannessfalse for Intel (or little) endiannessisMotorolaByteOrder in interface BufferReaderpublic short getUInt8(int index)
throws BufferBoundsException
BufferReadergetUInt8 in interface BufferReaderindex - 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
BufferReadergetInt8 in interface BufferReaderindex - 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
BufferReadergetUInt16 in interface BufferReaderindex - 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
BufferReadergetInt16 in interface BufferReaderindex - 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
BufferReadergetUInt32 in interface BufferReaderindex - 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
BufferReadergetInt32 in interface BufferReaderindex - 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
BufferReadergetInt64 in interface BufferReaderindex - 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 BufferReaderBufferBoundsExceptionpublic float getFloat32(int index)
throws BufferBoundsException
getFloat32 in interface BufferReaderBufferBoundsExceptionpublic double getDouble64(int index)
throws BufferBoundsException
getDouble64 in interface BufferReaderBufferBoundsExceptionpublic byte[] getBytes(int index,
int count)
throws BufferBoundsException
getBytes in interface BufferReaderBufferBoundsExceptionpublic String getString(int index, int bytesRequested) throws BufferBoundsException
getString in interface BufferReaderBufferBoundsExceptionpublic String getString(int index, int bytesRequested, String charset) throws BufferBoundsException
getString in interface BufferReaderBufferBoundsExceptionpublic String getNullTerminatedString(int index, int maxLengthBytes) throws BufferBoundsException
BufferReaderbyte=='\0' or where length==maxLength.getNullTerminatedString in interface BufferReaderindex - 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 © 2003-2012 Drew Noakes. All Rights Reserved.