public final class ParsableByteArray
extends java.lang.Object
| 构造器和说明 |
|---|
ParsableByteArray()
Creates a new instance that initially has no backing data.
|
ParsableByteArray(byte[] data)
Creates a new instance wrapping
data, and sets the limit to data.length. |
ParsableByteArray(byte[] data,
int limit)
Creates a new instance that wraps an existing array.
|
ParsableByteArray(int limit)
Creates a new instance with
limit bytes and sets the limit. |
| 限定符和类型 | 方法和说明 |
|---|---|
int |
bytesLeft()
Returns the number of bytes yet to be read.
|
int |
capacity()
Returns the capacity of the array, which may be larger than the limit.
|
void |
ensureCapacity(int requiredCapacity)
Ensures the backing array is at least
requiredCapacity long. |
byte[] |
getData()
Returns the underlying array.
|
int |
getPosition()
Returns the current offset in the array, in bytes.
|
int |
limit()
Returns the limit.
|
char |
peekChar()
Peeks at the next char.
|
int |
peekUnsignedByte()
Peeks at the next byte as an unsigned value.
|
void |
readBytes(byte[] buffer,
int offset,
int length)
Reads the next
length bytes into buffer at offset. |
void |
readBytes(java.nio.ByteBuffer buffer,
int length)
Reads the next
length bytes into buffer. |
void |
readBytes(ParsableBitArray bitArray,
int length)
Reads the next
length bytes into bitArray, and resets the position of
bitArray to zero. |
java.lang.String |
readDelimiterTerminatedString(char delimiter)
Reads up to the next delimiter byte (or the limit) as UTF-8 characters.
|
double |
readDouble()
Reads the next eight bytes as a 64-bit floating point value.
|
float |
readFloat()
Reads the next four bytes as a 32-bit floating point value.
|
int |
readInt()
Reads the next four bytes as a signed value
|
int |
readInt24()
Reads the next three bytes as a signed value.
|
java.lang.String |
readLine()
Reads a line of text.
|
int |
readLittleEndianInt()
Reads the next four bytes as a signed value in little endian order.
|
int |
readLittleEndianInt24()
Reads the next three bytes as a signed value in little endian order.
|
long |
readLittleEndianLong()
Reads the next eight bytes as a signed value in little endian order.
|
short |
readLittleEndianShort()
Reads the next two bytes as a signed value.
|
long |
readLittleEndianUnsignedInt()
Reads the next four bytes as an unsigned value in little endian order.
|
int |
readLittleEndianUnsignedInt24()
Reads the next three bytes as an unsigned value in little endian order.
|
int |
readLittleEndianUnsignedIntToInt()
Reads the next four bytes as a little endian unsigned integer into an integer, if the top bit
is a zero.
|
int |
readLittleEndianUnsignedShort()
Reads the next two bytes as an unsigned value.
|
long |
readLong()
Reads the next eight bytes as a signed value.
|
java.lang.String |
readNullTerminatedString()
Reads up to the next NUL byte (or the limit) as UTF-8 characters.
|
java.lang.String |
readNullTerminatedString(int length)
Reads the next
length bytes as UTF-8 characters. |
short |
readShort()
Reads the next two bytes as a signed value.
|
java.lang.String |
readString(int length)
Reads the next
length bytes as UTF-8 characters. |
java.lang.String |
readString(int length,
java.nio.charset.Charset charset)
Reads the next
length bytes as characters in the specified Charset. |
int |
readSynchSafeInt()
Reads a Synchsafe integer.
|
int |
readUnsignedByte()
Reads the next byte as an unsigned value.
|
int |
readUnsignedFixedPoint1616()
Reads the next four bytes, returning the integer portion of the fixed point 16.16 integer.
|
long |
readUnsignedInt()
Reads the next four bytes as an unsigned value.
|
int |
readUnsignedInt24()
Reads the next three bytes as an unsigned value.
|
int |
readUnsignedIntToInt()
Reads the next four bytes as an unsigned integer into an integer, if the top bit is a zero.
|
long |
readUnsignedLongToLong()
Reads the next eight bytes as an unsigned long into a long, if the top bit is a zero.
|
int |
readUnsignedShort()
Reads the next two bytes as an unsigned value.
|
long |
readUtf8EncodedLong()
Reads a long value encoded by UTF-8 encoding
|
void |
reset(byte[] data)
Updates the instance to wrap
data, and resets the position to zero and the limit to
data.length. |
void |
reset(byte[] data,
int limit)
Updates the instance to wrap
data, and resets the position to zero. |
void |
reset(int limit)
Resets the position to zero and the limit to the specified value.
|
void |
setLimit(int limit)
Sets the limit.
|
void |
setPosition(int position)
Sets the reading offset in the array.
|
void |
skipBytes(int bytes)
Moves the reading offset by
bytes. |
public ParsableByteArray()
public ParsableByteArray(int limit)
limit bytes and sets the limit.limit - The limit to set.public ParsableByteArray(byte[] data)
data, and sets the limit to data.length.data - The array to wrap.public ParsableByteArray(byte[] data,
int limit)
data - The data to wrap.limit - The limit to set.public void reset(int limit)
underlying array, potentially invalidating any local references.limit - The limit to set.public void reset(byte[] data)
data, and resets the position to zero and the limit to
data.length.data - The array to wrap.public void reset(byte[] data,
int limit)
data, and resets the position to zero.data - The array to wrap.limit - The limit to set.public void ensureCapacity(int requiredCapacity)
requiredCapacity long.
position, limit, and all data in the underlying
array (including that beyond limit()) are preserved.
This might replace or wipe the underlying array, potentially invalidating
any local references.
public int bytesLeft()
public int limit()
public void setLimit(int limit)
limit - The limit to set.public int getPosition()
public void setPosition(int position)
position - Byte offset in the array from which to read.java.lang.IllegalArgumentException - Thrown if the new position is neither in nor at the end of the
array.public byte[] getData()
Changes to this array are reflected in the results of the read...() methods.
This reference must be assumed to become invalid when reset(int) or ensureCapacity(int) are called (because the array might get reallocated).
public int capacity()
public void skipBytes(int bytes)
bytes.bytes - The number of bytes to skip.java.lang.IllegalArgumentException - Thrown if the new position is neither in nor at the end of the
array.public void readBytes(ParsableBitArray bitArray, int length)
length bytes into bitArray, and resets the position of
bitArray to zero.bitArray - The ParsableBitArray into which the bytes should be read.length - The number of bytes to write.public void readBytes(byte[] buffer,
int offset,
int length)
length bytes into buffer at offset.buffer - The array into which the read data should be written.offset - The offset in buffer at which the read data should be written.length - The number of bytes to read.System.arraycopy(Object, int, Object, int, int)public void readBytes(java.nio.ByteBuffer buffer,
int length)
length bytes into buffer.buffer - The ByteBuffer into which the read data should be written.length - The number of bytes to read.ByteBuffer.put(byte[], int, int)public int peekUnsignedByte()
public char peekChar()
public int readUnsignedByte()
public int readUnsignedShort()
public int readLittleEndianUnsignedShort()
public short readShort()
public short readLittleEndianShort()
public int readUnsignedInt24()
public int readInt24()
public int readLittleEndianInt24()
public int readLittleEndianUnsignedInt24()
public long readUnsignedInt()
public long readLittleEndianUnsignedInt()
public int readInt()
public int readLittleEndianInt()
public long readLong()
public long readLittleEndianLong()
public int readUnsignedFixedPoint1616()
public int readSynchSafeInt()
Synchsafe integers keep the highest bit of every byte zeroed. A 32 bit synchsafe integer can store 28 bits of information.
public int readUnsignedIntToInt()
java.lang.IllegalStateException - Thrown if the top bit of the input data is set.public int readLittleEndianUnsignedIntToInt()
java.lang.IllegalStateException - Thrown if the top bit of the input data is set.public long readUnsignedLongToLong()
java.lang.IllegalStateException - Thrown if the top bit of the input data is set.public float readFloat()
public double readDouble()
public java.lang.String readString(int length)
length bytes as UTF-8 characters.length - The number of bytes to read.public java.lang.String readString(int length,
java.nio.charset.Charset charset)
length bytes as characters in the specified Charset.length - The number of bytes to read.charset - The character set of the encoded characters.public java.lang.String readNullTerminatedString(int length)
length bytes as UTF-8 characters. A terminating NUL byte is discarded,
if present.length - The number of bytes to read.public java.lang.String readNullTerminatedString()
public java.lang.String readDelimiterTerminatedString(char delimiter)
public java.lang.String readLine()
A line is considered to be terminated by any one of a carriage return ('\r'), a line feed ('\n'), or a carriage return followed immediately by a line feed ('\r\n'). The UTF-8 charset is used. This method discards leading UTF-8 byte order marks, if present.
public long readUtf8EncodedLong()
java.lang.NumberFormatException - if there is a problem with decoding