public final class ByteBuffer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static byte |
DEFAULT_BUFFER_SIZE
The default size to initialize the
ByteBuffer with. |
Constructor and Description |
---|
ByteBuffer()
Construct a new
ByteBuffer with the default of DEFAULT_BUFFER_SIZE . |
ByteBuffer(byte[] bytes)
Create a new
ByteBuffer with the given byte array. |
ByteBuffer(int initialSize)
Initialize this buffer with the given initial size
|
Modifier and Type | Method and Description |
---|---|
void |
append(byte b)
Append a byte to the buffer.
|
void |
append(byte[] bytes)
Append a byte array to this buffer
|
void |
append(byte[] data,
int length)
Append the given byte array (of the length given, so you can pass in an array 100 bytes, but specify 50 to be added.
|
byte[] |
bytes()
Returns the bytes currently in this buffer.
|
byte[] |
bytesAndClear()
Returns the bytes that were added to this buffer.
|
void |
clear()
Clears the buffer of any existing data.
|
int |
length()
Returns the current length of the buffer
|
void |
setToSubData(int start,
int length)
Update the buffer to only contain the current data from the given start and length.
|
byte[] |
subData(int start,
int length)
Returns a byte array from this buffer from the given start index, and length
If length is less than 1, an empty byte array will be returned.
|
public static final byte DEFAULT_BUFFER_SIZE
ByteBuffer
with.public ByteBuffer(int initialSize)
public ByteBuffer(byte[] bytes)
ByteBuffer
with the given byte array. Note, the byte array is cloned before inserting
into the buffer.public ByteBuffer()
ByteBuffer
with the default of DEFAULT_BUFFER_SIZE
.public final void clear()
public final void append(byte b)
public final void append(byte[] bytes)
public final void append(byte[] data, int length)
public final void setToSubData(int start, int length)
public final byte[] subData(int start, int length)
public final int length()
public final byte[] bytes()
public final byte[] bytesAndClear()