Package io.pravega.common.util
Class CircularBuffer
- java.lang.Object
-
- io.pravega.common.util.CircularBuffer
-
public class CircularBuffer extends java.lang.ObjectConvenience class wrapping byteBuffer to provide a circular buffer. This works by maintaining two byte buffers backed by the same array. The position of the readBuffer corresponds to the point up to which data has been read. The position of the writeBuffer corresponds to the point up to which data has been written. Each buffer's limit is either the end or the buffer or the position of the other, depending on where the data has wrapped.
-
-
Constructor Summary
Constructors Constructor Description CircularBuffer(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcapacityAvailable()voidclear()intdataAvailable()Gets the number of bytes that can be read.intfill(java.nio.ByteBuffer fillFrom)Copies from the given ByteBuffer.intfill(java.nio.ByteBuffer[] fillFrom)Copies from the given ByteBuffers.intgetCapacity()intread(java.nio.ByteBuffer toFill)Copies into the given ByteBuffer.java.lang.StringtoString()
-
-
-
Method Detail
-
clear
public void clear()
-
read
public int read(java.nio.ByteBuffer toFill)
Copies into the given ByteBuffer.- Parameters:
toFill- The ByteBuffer to fill into.- Returns:
- the number of bytes put into toFill
-
fill
public int fill(java.nio.ByteBuffer fillFrom)
Copies from the given ByteBuffer.- Parameters:
fillFrom- The ByteBuffer to read from.- Returns:
- the number of bytes read from fillFrom
-
fill
public int fill(java.nio.ByteBuffer[] fillFrom)
Copies from the given ByteBuffers.- Parameters:
fillFrom- An array of ByteBuffer to read from.- Returns:
- the number of bytes read from fillFrom
-
dataAvailable
public int dataAvailable()
Gets the number of bytes that can be read.- Returns:
- Integer indicating the number of bytes that can be read.
-
capacityAvailable
public int capacityAvailable()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getCapacity
public int getCapacity()
-
-