Package org.jenkinsci.remoting.util
Class ByteBufferQueue
java.lang.Object
org.jenkinsci.remoting.util.ByteBufferQueue
A helper class to make queuing up of data easier.
- Since:
- 3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyteget()Reads the next byte from this queue.intget(byte[] dst, int offset, int len) This method transfers bytes from the head of this buffer queue into the given destinationbyte.voidget(ByteBuffer dst) This method transfers bytes from the head of this buffer queue into the given destination buffer.booleanTells whether there are any bytes between the current read index and the write index.booleanhasRemaining(int len) Tells whether there are any bytes between the current read index and the write index.Creates a new byte buffer matched to the queue's current buffer size.voidpeek(ByteBuffer dst) voidput(byte b) This method appends a single byte onto this buffer queue.voidput(byte[] src, int offset, int len) This method appends bytes from the byte array onto this buffer queue.voidput(ByteBuffer src) This method transfers the bytes remaining in the given source buffer appended onto this buffer queue.longReturns how much data is remaining between the current read index and the write index.intremaining(int limit) Returns how much data is remaining between the current read index and the write index.longskip(long bytes) Discards up to the specified number of bytes from the read index.byte[]Transfers all the bytes in theByteBufferQueuefrom the read position to the write position into a newbyte[].toString()voidunget(ByteBuffer src) This method transfers the bytes remaining in the given source buffer inserted at the head of this buffer queue.
-
Constructor Details
-
ByteBufferQueue
public ByteBufferQueue(int bufferSize) Constructor.- Parameters:
bufferSize- the size of buffers to use for queuing.
-
-
Method Details
-
newByteBuffer
Creates a new byte buffer matched to the queue's current buffer size.- Returns:
- a new byte buffer matched to the queue's current buffer size.
-
put
This method transfers the bytes remaining in the given source buffer appended onto this buffer queue.- Parameters:
src- The source buffer from which bytes are to be read.
-
put
public void put(byte[] src, int offset, int len) This method appends bytes from the byte array onto this buffer queue.- Parameters:
src- the source byte array.offset- the offset from which to start taking bytes.len- the number of bytes to transfer.
-
put
public void put(byte b) This method appends a single byte onto this buffer queue.- Parameters:
b- the byte.
-
hasRemaining
public boolean hasRemaining()Tells whether there are any bytes between the current read index and the write index.- Returns:
trueif, and only if, there is at least one byte remaining in this buffer queue.
-
hasRemaining
public boolean hasRemaining(int len) Tells whether there are any bytes between the current read index and the write index.- Parameters:
len- the number of bytes that we want at least remaining- Returns:
trueif, and only if, there is at least len bytes remaining in this buffer queue.
-
remaining
public long remaining()Returns how much data is remaining between the current read index and the write index.- Returns:
- the total number of bytes remaining in this buffer queue.
-
remaining
public int remaining(int limit) Returns how much data is remaining between the current read index and the write index.- Parameters:
limit- the maximum number of remaining bytes at which to short-circuit.- Returns:
- the total number of bytes remaining in this buffer queue or the supplied maximum if there is at least the supplied limit remaining.
-
skip
public long skip(long bytes) Discards up to the specified number of bytes from the read index.- Parameters:
bytes- the total number of bytes to discard.- Returns:
- the number of bytes actually discarded.
-
peek
-
get
This method transfers bytes from the head of this buffer queue into the given destination buffer. The number of bytes transferred will be the smaller of the number of bytes available and the remaining capacity of the destination buffer.- Parameters:
dst- the destination buffer into which bytes are to be written.
-
get
public int get(byte[] dst, int offset, int len) This method transfers bytes from the head of this buffer queue into the given destinationbyte. The number of bytes transferred will be the smaller of the number of requested bytes and the remaining capacity of the destination buffer.- Parameters:
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.- Returns:
- the actual number of bytes transferred.
-
get
public byte get()Reads the next byte from this queue.- Returns:
- The byte at the read index.
- Throws:
BufferUnderflowException- If there are no remaining bytes to be read.
-
unget
This method transfers the bytes remaining in the given source buffer inserted at the head of this buffer queue.- Parameters:
src- The source buffer from which bytes are to be read.
-
toString
-
toByteArray
public byte[] toByteArray()Transfers all the bytes in theByteBufferQueuefrom the read position to the write position into a newbyte[].- Returns:
- the
byte[]
-