Class CircularBuffer


  • public class CircularBuffer
    extends java.lang.Object
    Convenience 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
      int capacityAvailable()  
      void clear()  
      int dataAvailable()
      Gets the number of bytes that can be read.
      int fill​(java.nio.ByteBuffer fillFrom)
      Copies from the given ByteBuffer.
      int fill​(java.nio.ByteBuffer[] fillFrom)
      Copies from the given ByteBuffers.
      int getCapacity()  
      int read​(java.nio.ByteBuffer toFill)
      Copies into the given ByteBuffer.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • CircularBuffer

        public CircularBuffer​(int capacity)
    • 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:
        toString in class java.lang.Object
      • getCapacity

        public int getCapacity()