Package com.drew.lang

Class StreamReader


public class StreamReader extends SequentialReader
Author:
Drew Noakes https://drewnoakes.com
  • Constructor Details

    • StreamReader

      public StreamReader(InputStream stream)
  • Method Details

    • getPosition

      public long getPosition()
      Specified by:
      getPosition in class SequentialReader
    • getByte

      public byte getByte() throws IOException
      Description copied from class: SequentialReader
      Gets the next byte in the sequence.
      Specified by:
      getByte in class SequentialReader
      Returns:
      The read byte value
      Throws:
      IOException
    • getBytes

      public byte[] getBytes(int count) throws IOException
      Description copied from class: SequentialReader
      Returns the required number of bytes from the sequence.
      Specified by:
      getBytes in class SequentialReader
      Parameters:
      count - The number of bytes to be returned
      Returns:
      The requested bytes
      Throws:
      IOException
    • getBytes

      public void getBytes(byte[] buffer, int offset, int count) throws IOException
      Description copied from class: SequentialReader
      Retrieves bytes, writing them into a caller-provided buffer.
      Specified by:
      getBytes in class SequentialReader
      Parameters:
      buffer - The array to write bytes to.
      offset - The starting position within buffer to write to.
      count - The number of bytes to be written.
      Throws:
      IOException
    • skip

      public void skip(long n) throws IOException
      Description copied from class: SequentialReader
      Skips forward in the sequence. If the sequence ends, an EOFException is thrown.
      Specified by:
      skip in class SequentialReader
      Parameters:
      n - the number of byte to skip. Must be zero or greater.
      Throws:
      EOFException - the end of the sequence is reached.
      IOException - an error occurred reading from the underlying source.
    • trySkip

      public boolean trySkip(long n) throws IOException
      Description copied from class: SequentialReader
      Skips forward in the sequence, returning a boolean indicating whether the skip succeeded, or whether the sequence ended.
      Specified by:
      trySkip in class SequentialReader
      Parameters:
      n - the number of byte to skip. Must be zero or greater.
      Returns:
      a boolean indicating whether the skip succeeded, or whether the sequence ended.
      Throws:
      IOException - an error occurred reading from the underlying source.
    • available

      public int available()
      Description copied from class: SequentialReader
      Returns an estimate of the number of bytes that can be read (or skipped over) from this SequentialReader without blocking by the next invocation of a method for this input stream. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

      Note that while some implementations of SequentialReader like SequentialByteArrayReader will return the total remaining number of bytes in the stream, others will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

      Specified by:
      available in class SequentialReader
      Returns:
      an estimate of the number of bytes that can be read (or skipped over) from this SequentialReader without blocking or 0 when it reaches the end of the input stream.