public final class ReadableBytes extends Object
A readable wrapper for an array of bytes.
Reads from the wrapped byte array while advancing an internal offset.
Modifier and Type | Field and Description |
---|---|
protected byte[] |
bytes
The wrapped immutable array of bytes.
|
protected int |
offset
A mutable offset into the array of bytes.
|
Constructor and Description |
---|
ReadableBytes(byte[] bytes,
int offset)
Create ReadableBytes.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getBytes()
Returns the bytes.
|
int |
getOffset()
Returns the offset.
|
boolean |
readBoolean()
Read a boolean.
|
byte |
readByte()
Read a byte.
|
void |
readBytes(byte[] ba,
int off,
int len)
Read into an array of bytes.
|
byte[] |
readBytes(int len)
Read an array of bytes.
|
char |
readChar()
Read a char.
|
char[] |
readChars(int len)
Read an array of char.
|
double |
readDouble()
Read a double.
|
float |
readFloat()
Read a float.
|
int |
readInt()
Read an int.
|
long |
readLong()
Read a long.
|
String |
readString()
Read string.
|
String |
readString(int l)
Read string.
|
int |
remaining()
Returns the number of bytes after the offset.
|
void |
rewind()
Sets the offset to 0.
|
void |
skip(int length)
Advance the offset.
|
protected byte[] bytes
protected int offset
public ReadableBytes(byte[] bytes, int offset)
bytes
- The bytes to be wrapped.offset
- An offset.public int getOffset()
public byte[] getBytes()
public int remaining()
public void rewind()
public void skip(int length)
length
- The number of bytes to be skipped over.public byte readByte()
public boolean readBoolean()
public byte[] readBytes(int len)
len
- The number of bytes to be read.public void readBytes(byte[] ba, int off, int len)
ba
- The array of bytes to be read into.off
- The offset into the array of bytes to be read into.len
- The number of bytes to be read.public int readInt()
public char readChar()
public long readLong()
public char[] readChars(int len)
len
- The number of char to be read.public String readString(int l)
l
- The number of bytes to be read (2 * the number of characters) or -1.public String readString()
public float readFloat()
public double readDouble()
Copyright © 2013. All Rights Reserved.