Package com.drew.lang

Class RandomAccessStreamReader

java.lang.Object
com.drew.lang.RandomAccessReader
com.drew.lang.RandomAccessStreamReader

public class RandomAccessStreamReader extends RandomAccessReader
Author:
Drew Noakes https://drewnoakes.com
  • Field Details

  • Constructor Details

    • RandomAccessStreamReader

      public RandomAccessStreamReader(InputStream stream)
    • RandomAccessStreamReader

      public RandomAccessStreamReader(InputStream stream, int chunkLength)
    • RandomAccessStreamReader

      public RandomAccessStreamReader(InputStream stream, int chunkLength, long streamLength)
  • Method Details

    • getLength

      public long getLength() throws IOException
      Reads to the end of the stream, in order to determine the total number of bytes. In general, this is not a good idea for this implementation of RandomAccessReader.
      Specified by:
      getLength in class RandomAccessReader
      Returns:
      the length of the data source, in bytes.
      Throws:
      IOException
    • toUnshiftedOffset

      public int toUnshiftedOffset(int localOffset)
      Specified by:
      toUnshiftedOffset in class RandomAccessReader
    • getByte

      public byte getByte(int index) throws IOException
      Description copied from class: RandomAccessReader
      Gets the byte value at the specified byte index.

      Implementations should not perform any bounds checking in this method. That should be performed in validateIndex and isValidIndex.

      Specified by:
      getByte in class RandomAccessReader
      Parameters:
      index - The index from which to read the byte
      Returns:
      The read byte value
      Throws:
      BufferBoundsException - if the requested byte is beyond the end of the underlying data source
      IOException - if the byte is unable to be read
    • getBytes

      public byte[] getBytes(int index, int count) throws IOException
      Description copied from class: RandomAccessReader
      Returns the required number of bytes from the specified index from the underlying source.
      Specified by:
      getBytes in class RandomAccessReader
      Parameters:
      index - The index from which the bytes begins in the underlying source
      count - The number of bytes to be returned
      Returns:
      The requested bytes
      Throws:
      BufferBoundsException - if the requested bytes extend beyond the end of the underlying data source
      IOException - if the byte is unable to be read