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 Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
    Internal array for the data.
    private final int
    Maximum size of the internal array (one plus the maximum capacity of the buffer).
    private int
    Next read position.
    private int
    Next write position.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CircularBuffer(int size, int maxSize)
    Creates a new circular buffer of the given size.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Data available in the buffer for reading.
    private void
     
    (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
     
    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.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

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