Package net.schmizz.sshj.common
Class CircularBuffer<T extends CircularBuffer<T>>
java.lang.Object
net.schmizz.sshj.common.CircularBuffer<T>
- Direct Known Subclasses:
CircularBuffer.PlainCircularBuffer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static final class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCircularBuffer
(int size, int maxSize) Creates a new circular buffer of the given size. -
Method Summary
Modifier and TypeMethodDescriptionint
Data available in the buffer for reading.private void
ensureAvailable
(int a) (package private) void
ensureCapacity
(int capacity) If the internal array does not have room for "capacity" more bytes, resizes the array to make that room.private int
getNextSize
(int currentSize) Determines the size to which to grow the internal array.(package private) int
length()
int
Returns how many more bytes this buffer can receive.putRawBytes
(byte[] source, int offset, int length) Writes data to this buffer from the provided array.void
readRawBytes
(byte[] destination, int offset, int length) Reads data from this buffer into the provided array.toString()
-
Field Details
-
maxSize
private final int maxSizeMaximum size of the internal array (one plus the maximum capacity of the buffer). -
data
private byte[] dataInternal array for the data. All bytes minus one can be used to avoid empty vs full ambiguity when rpos == wpos. -
rpos
private int rposNext read position. Wraps around the end of the internal array. When it reaches wpos, the buffer becomes empty. Can take the value data.length, which is equivalent to 0. -
wpos
private int wposNext write position. Wraps around the end of the internal array. If it is equal to rpos, then the buffer is empty; the code does not allow wpos to reach rpos from the left. This implies that the buffer can store up to data.length - 1 bytes. Can take the value data.length, which is equivalent to 0.
-
-
Constructor Details
-
CircularBuffer
public CircularBuffer(int size, int maxSize) Creates a new circular buffer of the given size. The capacity of the buffer is one less than the size/
-
-
Method Details
-
getNextSize
private int getNextSize(int currentSize) Determines the size to which to grow the internal array. -
available
public int available()Data available in the buffer for reading. -
ensureAvailable
-
maxPossibleRemainingCapacity
public int maxPossibleRemainingCapacity()Returns how many more bytes this buffer can receive. -
ensureCapacity
If the internal array does not have room for "capacity" more bytes, resizes the array to make that room. -
readRawBytes
public void readRawBytes(byte[] destination, int offset, int length) throws CircularBuffer.CircularBufferException Reads data from this buffer into the provided array. -
putRawBytes
public T putRawBytes(byte[] source, int offset, int length) throws CircularBuffer.CircularBufferException Writes data to this buffer from the provided array. -
length
int length() -
toString
-