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
public class CircularBuffer<T extends CircularBuffer<T>> extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CircularBuffer.CircularBufferException
static class
CircularBuffer.PlainCircularBuffer
-
Constructor Summary
Constructors Constructor Description CircularBuffer(int size, int maxSize)
Creates a new circular buffer of the given size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
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
maxPossibleRemainingCapacity()
Returns how many more bytes this buffer can receive.T
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.java.lang.String
toString()
-
-
-
Field Detail
-
maxSize
private final int maxSize
Maximum size of the internal array (one plus the maximum capacity of the buffer).
-
data
private byte[] data
Internal array for the data. All bytes minus one can be used to avoid empty vs full ambiguity when rpos == wpos.
-
rpos
private int rpos
Next 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 wpos
Next 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.
-
-
Method Detail
-
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
private void ensureAvailable(int a) throws CircularBuffer.CircularBufferException
-
maxPossibleRemainingCapacity
public int maxPossibleRemainingCapacity()
Returns how many more bytes this buffer can receive.
-
ensureCapacity
void ensureCapacity(int capacity) throws CircularBuffer.CircularBufferException
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-