Class LinkedBuffer


  • public class LinkedBuffer
    extends java.lang.Object
    Implements an element of a linked list that contains a byte array
    Author:
    Roi Blanco
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] buffer
      The internal buffer.
      protected int bufferSize
      The size of the internal buffer
      static int DEFAULT_BUFFER_SIZE
      The default size of the internal buffer in bytes The buffer has to be big enough to allocate a single write, i.e we cannot write *at once* more than bufferSize bytes
      protected LinkedBuffer next
      The next buffer in the list
    • Constructor Summary

      Constructors 
      Constructor Description
      LinkedBuffer()
      Default Constructor.
      LinkedBuffer​(int _bufferSize)
      Constructor
    • Field Detail

      • buffer

        protected byte[] buffer
        The internal buffer.
      • bufferSize

        protected int bufferSize
        The size of the internal buffer
      • DEFAULT_BUFFER_SIZE

        public static final int DEFAULT_BUFFER_SIZE
        The default size of the internal buffer in bytes The buffer has to be big enough to allocate a single write, i.e we cannot write *at once* more than bufferSize bytes
        See Also:
        Constant Field Values
      • next

        protected LinkedBuffer next
        The next buffer in the list
    • Constructor Detail

      • LinkedBuffer

        public LinkedBuffer()
        Default Constructor. Uses a buffer of DEFAULT_BUFFER_SIZE bytes size.
      • LinkedBuffer

        public LinkedBuffer​(int _bufferSize)
        Constructor
        Parameters:
        _bufferSize - size in bytes of the buffer.
    • Method Detail

      • getNext

        public LinkedBuffer getNext()
        Returns:
        the next linked buffer in the list (or null)
      • setNext

        public void setNext​(LinkedBuffer _next)
        Set the next buffer in the list
        Parameters:
        _next - next LinkedBuffer in the list
      • write

        public boolean write​(int b)
                      throws java.io.IOException
        Writes a byte in the buffer
        Parameters:
        b - int containing the byte to write
        Returns:
        true iff the buffer has used all its capacity
        Throws:
        java.io.IOException
      • writeByte

        public boolean writeByte​(byte b)
                          throws java.io.IOException
        Writes a byte in the buffer
        Parameters:
        b - byte to write
        Returns:
        true iff the buffer has used all its capacity
        Throws:
        java.io.IOException
      • getBufferSize

        public int getBufferSize()
        Returns:
        The size of the buffer
      • getPosition

        public int getPosition()
        Returns:
        The current position in the buffer
      • getBuffer

        public byte[] getBuffer()
        Returns:
        The byte buffer (byte[])