java.lang.Object
i2p.susi.util.ReadBuffer
All Implemented Interfaces:
Buffer

public class ReadBufferextends Object implements Buffer
Read-only Buffer for constant data initialized from a byte array. See MemoryBuffer for read/write support.
  • Field Details

    • content

      public final byte[] content
      The backing byte array the window is read from.
    • length

      public final int length
      The number of readable bytes in the window.
    • offset

      public final int offset
      The index within the backing array where the window starts.
  • Constructor Details

    • ReadBuffer

      public ReadBuffer(byte[] content, int offset, int length)
      Create a ReadBuffer for a portion of a byte array.
      Parameters:
      content - the byte array containing the data
      offset - the start offset within the array
      length - the number of bytes from offset
  • Method Details

    • getInputStream

      public InputStream getInputStream()
      Stream for reading the buffered data.
      Specified by:
      getInputStream in interface Buffer
      Returns:
      new ByteArrayInputStream over the content
    • getOutputStream

      public OutputStream getOutputStream()
      Stream for writing data to be buffered.
      Specified by:
      getOutputStream in interface Buffer
      Returns:
      the output stream
      Throws:
      IllegalStateException - always; this buffer is read-only and wraps a fixed byte array, so it has nowhere to write
    • readComplete

      public void readComplete(boolean success)
      Does nothing.
      Specified by:
      readComplete in interface Buffer
      Parameters:
      success - if false, the read is considered failed
    • writeComplete

      public void writeComplete(boolean success)
      Does nothing.
      Specified by:
      writeComplete in interface Buffer
      Parameters:
      success - if false, deletes any resources
    • getLength

      public int getLength()
      Always valid.
      Specified by:
      getLength in interface Buffer
      Returns:
      the number of bytes in the window, as given to the constructor
    • getOffset

      public int getOffset()
      Always valid.
      Specified by:
      getOffset in interface Buffer
      Returns:
      the index in the backing array where the window starts, as given to the constructor
    • toString

      public String toString()
      Decodes the window as UTF-8, or returns an empty string when there is no backing array.
      Overrides:
      toString in class Object