Class RandomAccessReadDataStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    class RandomAccessReadDataStream
    extends TTFDataStream
    An implementation of the TTFDataStream using RandomAccessRead as source. The underlying RandomAccessRead can be any length, but this implementation supports only bufferLengths upto Integer.MAX_VALUE.
    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • length

        private final long length
      • data

        private final byte[] data
      • currentPosition

        private int currentPosition
    • Constructor Detail

      • RandomAccessReadDataStream

        RandomAccessReadDataStream​(RandomAccessRead randomAccessRead)
                            throws java.io.IOException
        Constructor.
        Parameters:
        randomAccessRead - source to be read from. Caller should close it.
        Throws:
        java.io.IOException - If there is a problem reading the source data.
      • RandomAccessReadDataStream

        RandomAccessReadDataStream​(java.io.InputStream inputStream)
                            throws java.io.IOException
        Constructor.
        Parameters:
        inputStream - source to be read from. Caller should close it.
        Throws:
        java.io.IOException - If there is a problem reading the source data.
    • Method Detail

      • getCurrentPosition

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

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

        public int read()
                 throws java.io.IOException
        Read an unsigned byte.
        Specified by:
        read in class TTFDataStream
        Returns:
        An unsigned byte, or -1, signalling 'no more data'
        Throws:
        java.io.IOException - If there is an error reading the data.
      • readLong

        public final long readLong()
                            throws java.io.IOException
        Read a signed 64-bit integer.
        Specified by:
        readLong in class TTFDataStream
        Returns:
        eight bytes interpreted as a long.
        Throws:
        java.io.IOException - If there is an error reading the data.
      • readInt

        private int readInt()
                     throws java.io.IOException
        Read a signed 32-bit integer.
        Returns:
        4 bytes interpreted as an int.
        Throws:
        java.io.IOException - If there is an error reading the data.
      • seek

        public void seek​(long pos)
                  throws java.io.IOException
        Seek into the datasource. When the requested pos is < 0, an IOException() is fired. When the requested pos is ≥ length, the currentPosition is set to the first byte after the data!
        Specified by:
        seek in class TTFDataStream
        Parameters:
        pos - The position to seek to.
        Throws:
        java.io.IOException - If there is an error seeking to that position.
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.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, signalling 'no more data'
        Throws:
        java.io.IOException - If there is an error reading from the stream.
        See Also:
        InputStream.read( byte[], int, int )
      • 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
      • getOriginalData

        public java.io.InputStream getOriginalData()
                                            throws java.io.IOException
        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:
        java.io.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.