@NotThreadSafe public class ByteBufferQueue extends Object
| Constructor and Description |
|---|
ByteBufferQueue(int bufferSize)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
byte |
get()
Reads the next byte from this queue.
|
int |
get(byte[] dst,
int offset,
int len)
This method transfers bytes from the head of this buffer queue into the given destination
byte[]. |
void |
get(ByteBuffer dst)
This method transfers bytes from the head of this buffer queue into the given destination buffer.
|
boolean |
hasRemaining()
Tells whether there are any bytes between the current read index and
the write index.
|
boolean |
hasRemaining(int len)
Tells whether there are any bytes between the current read index and
the write index.
|
ByteBuffer |
newByteBuffer()
Creates a new byte buffer matched to the queue's current buffer size.
|
void |
peek(ByteBuffer dst) |
void |
put(byte b)
This method appends a single byte onto this buffer queue.
|
void |
put(byte[] src,
int offset,
int len)
This method appends bytes from the byte array onto this buffer queue.
|
void |
put(ByteBuffer src)
This method transfers the bytes remaining in the given source
buffer appended onto this buffer queue.
|
long |
remaining()
Returns how much data is remaining between the current read index and the write index.
|
int |
remaining(int limit)
Returns how much data is remaining between the current read index and the write index.
|
long |
skip(long bytes)
Discards up to the specified number of bytes from the read index.
|
byte[] |
toByteArray()
Transfers all the bytes in the
ByteBufferQueue from the read position to the write position into a new
byte[]. |
String |
toString() |
void |
unget(ByteBuffer src)
This method transfers the bytes remaining in the given source buffer inserted at the head of this buffer queue.
|
public ByteBufferQueue(int bufferSize)
bufferSize - the size of buffers to use for queuing.public ByteBuffer newByteBuffer()
public void put(ByteBuffer src)
src - The source buffer from which bytes are to be read.public void put(byte[] src,
int offset,
int len)
src - the source byte array.offset - the offset from which to start taking bytes.len - the number of bytes to transfer.public void put(byte b)
b - the byte.public boolean hasRemaining()
public boolean hasRemaining(int len)
len - the number of bytes that we want at least remainingpublic long remaining()
public int remaining(int limit)
limit - the maximum number of remaining bytes at which to short-circuit.public long skip(long bytes)
bytes - the total number of bytes to discard.public void peek(ByteBuffer dst)
public void get(ByteBuffer dst)
dst - the destination buffer into which bytes are to be written.public int get(byte[] dst,
int offset,
int len)
byte[].
The number of bytes transferred will be the smaller of the number of requested bytes and the remaining capacity
of the destination buffer.dst - the destination byte array into which the bytes are to be written.offset - the offset in the byte array at which to write the bytes.len - the number of bytes to transfer.public byte get()
BufferUnderflowException - If there are no remaining bytes to be read.public void unget(ByteBuffer src)
src - The source buffer from which bytes are to be read.public byte[] toByteArray()
ByteBufferQueue from the read position to the write position into a new
byte[].byte[]Copyright © 2004–2017. All rights reserved.