Class CircularBuffer<T extends CircularBuffer<T>>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] data
      Internal array for the data.
      private int maxSize
      Maximum size of the internal array (one plus the maximum capacity of the buffer).
      private int rpos
      Next read position.
      private int wpos
      Next write position.
    • 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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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.
    • Constructor Detail

      • 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/