Class RandomAccessReadUnbufferedDataStream

java.lang.Object
org.apache.fontbox.ttf.TTFDataStream
org.apache.fontbox.ttf.RandomAccessReadUnbufferedDataStream
All Implemented Interfaces:
Closeable, AutoCloseable

class RandomAccessReadUnbufferedDataStream extends TTFDataStream
In contrast to RandomAccessReadDataStream, this class doesn't pre-load RandomAccessRead into a byte[], it works with RandomAccessRead directly. Performance: it is much faster if most of the buffer is skipped, and slower if whole buffer is read()
  • Field Details

    • length

      private final long length
    • randomAccessRead

      private final RandomAccessRead randomAccessRead
  • Constructor Details

    • RandomAccessReadUnbufferedDataStream

      RandomAccessReadUnbufferedDataStream(RandomAccessRead randomAccessRead) throws IOException
      Throws:
      IOException - If there is a problem reading the source length.
  • Method Details

    • getCurrentPosition

      public long getCurrentPosition() throws IOException
      Get the current position in the stream.
      Specified by:
      getCurrentPosition in class TTFDataStream
      Returns:
      The current position in the stream.
      Throws:
      IOException - If an error occurs while reading the stream.
    • close

      public void close() throws IOException
      Close the underlying resources.
      Throws:
      IOException - If there is an error closing the resources.
    • read

      public int read() throws IOException
      Read an unsigned byte.
      Specified by:
      read in class TTFDataStream
      Returns:
      An unsigned byte.
      Throws:
      IOException - If there is an error reading the data.
    • readLong

      public final long readLong() throws IOException
      Read an unsigned byte.
      Specified by:
      readLong in class TTFDataStream
      Returns:
      An unsigned byte.
      Throws:
      IOException - If there is an error reading the data.
    • readInt

      private int readInt() throws IOException
      Throws:
      IOException
    • seek

      public void seek(long pos) throws IOException
      Seek into the datasource.
      Specified by:
      seek in class TTFDataStream
      Parameters:
      pos - The position to seek to.
      Throws:
      IOException - If there is an error seeking to that position.
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Specified by:
      read in class TTFDataStream
      Parameters:
      b - The buffer to write to.
      off - The offset into the buffer.
      len - The length into the buffer.
      Returns:
      The number of bytes read, or -1 at the end of the stream
      Throws:
      IOException - If there is an error reading from the stream.
      See Also:
    • getOriginalData

      public InputStream getOriginalData() throws IOException
      Lifetime of returned InputStream is bound by this lifetime, it won't close underlying RandomAccessRead. This will get the original data file that was used for this stream.
      Specified by:
      getOriginalData in class TTFDataStream
      Returns:
      The data that was read from.
      Throws:
      IOException - If there is an issue reading the data.
    • getOriginalDataSize

      public long getOriginalDataSize()
      This will get the original data size that was used for this stream.
      Specified by:
      getOriginalDataSize in class TTFDataStream
      Returns:
      The size of the original data.
    • createSubView

      public RandomAccessRead createSubView(long length)
      Description copied from class: TTFDataStream
      Creates a view from current position to pos + length. It can be faster than read(length) if you only need a few bytes. SubView.close() should never close TTFDataStream.this, only itself.
      Overrides:
      createSubView in class TTFDataStream
      Returns:
      A view or null (caller can use TTFDataStream.read() instead). Please close() the result