Class ByteData.Reader

All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
ByteData

public static final class ByteData.Reader extends ByteArrayInputStream
Reads out the data from an underlying ByteData instance.

Instances are thread safe and fully support InputStream.available() and mark/reset.

  • Method Details

    • read

      public int read(byte[] b)
      Overrides:
      read in class InputStream
    • readNBytes

      public byte[] readNBytes(int len)
      Overrides:
      readNBytes in class InputStream
    • skipNBytes

      public void skipNBytes(long n)
      Overrides:
      skipNBytes in class InputStream
    • peek

      public int peek()
      Peek at the next byte.

      This does not change the current read offset.

      Returns:
      next byte (0-255)
      Throws:
      IndexOutOfBoundsException - if there are no more bytes
    • readByte

      public int readByte()
      Read the next byte as an unsigned value.
      Returns:
      next byte (0-255)
      Throws:
      IndexOutOfBoundsException - if there are no more bytes
    • unread

      public void unread()
      Unread the previously read byte.

      Equivalent to unread(1).

      Throws:
      IndexOutOfBoundsException - if zero bytes have been read
    • unread

      public void unread(int len)
      Unread the specified number of previously read bytes.

      Upon return this instance's current offset will be decremented by len bytes.

      Parameters:
      len - the number of bytes to unread
      Throws:
      IndexOutOfBoundsException - if len is negative or greater than the number of bytes that have been read
    • remain

      public int remain()
      Get the number of bytes remaining.
      Returns:
      bytes remaining
    • getOffset

      public int getOffset()
      Get the current offset into the underlying data.
      Returns:
      current offset
    • readBytes

      public ByteData readBytes(int len)
      Read out the specified number of bytes.
      Parameters:
      len - number of bytes to read
      Returns:
      the next len bytes
      Throws:
      IndexOutOfBoundsException - if len is negative or greater than the number of bytes remaining
    • dataReadSoFar

      public ByteData dataReadSoFar()
      Obtain a ByteData instance containing all of the data read from this instance so far.

      This does not change the current read offset.

      Returns:
      all data read so far
    • dataNotYetRead

      public ByteData dataNotYetRead()
      Obtain a ByteData instance containing all of the data read not yet read from this instance.

      This does not change the current read offset.

      Returns:
      all unread data
    • readRemaining

      public ByteData readRemaining()
      Read out all remaining bytes.

      Upon return this instance's current offset will be positioned at the end of the data.

      Returns:
      bytes read
    • getByteData

      public ByteData getByteData()
      Obtain the original ByteData instance from which this reader was created.

      This does not change the current read offset.

      Returns:
      the entire underlying data