Class DataInputRandomAccessRead

  • All Implemented Interfaces:
    DataInput

    public class DataInputRandomAccessRead
    extends java.lang.Object
    implements DataInput
    This class implements the DataInput interface using a RandomAccessRead as source.
    Note: things can get hairy when the underlying buffer is larger than Integer.MAX_VALUE. Straight forward reading may work, but getPosition() and setPosition(int) may have problems.
    • Constructor Summary

      Constructors 
      Constructor Description
      DataInputRandomAccessRead​(org.apache.pdfbox.io.RandomAccessRead randomAccessRead)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getPosition()
      Returns the current position.
      boolean hasRemaining()
      Determines if there are any bytes left to read or not.
      int length()  
      int peekUnsignedByte​(int offset)
      Peeks one single unsigned byte from the buffer.
      byte readByte()
      Read one single byte from the buffer.
      byte[] readBytes​(int length)
      Read a number of single byte values from the buffer.
      Note: when readBytes(5) is called, but there are only 3 bytes available, the caller gets an IOException, not the 3 bytes!
      int readUnsignedByte()
      Read one single unsigned byte from the buffer.
      void setPosition​(int position)
      Sets the current absolute position to the given value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DataInputRandomAccessRead

        public DataInputRandomAccessRead​(org.apache.pdfbox.io.RandomAccessRead randomAccessRead)
        Constructor.
        Parameters:
        randomAccessRead - the source to be read from
    • Method Detail

      • hasRemaining

        public boolean hasRemaining()
                             throws java.io.IOException
        Determines if there are any bytes left to read or not.
        Specified by:
        hasRemaining in interface DataInput
        Returns:
        true if there are any bytes left to read.
        Throws:
        java.io.IOException - when the underlying buffer has already been closed.
      • getPosition

        public int getPosition()
                        throws java.io.IOException
        Returns the current position.
        Specified by:
        getPosition in interface DataInput
        Returns:
        current position.
        Throws:
        java.io.IOException - when the underlying buffer has already been closed.
      • setPosition

        public void setPosition​(int position)
                         throws java.io.IOException
        Sets the current absolute position to the given value. You cannot use setPosition(-20) to move 20 bytes back!
        Specified by:
        setPosition in interface DataInput
        Parameters:
        position - the given position, must be 0 ≤ position < length.
        Throws:
        java.io.IOException - if the new position is out of rangeor when the underlying buffer has already been closed.
      • readByte

        public byte readByte()
                      throws java.io.IOException
        Read one single byte from the buffer.
        Specified by:
        readByte in interface DataInput
        Returns:
        the byte.
        Throws:
        java.io.IOException - when there are no bytes to read or when the underlying buffer has already been closed.
      • readUnsignedByte

        public int readUnsignedByte()
                             throws java.io.IOException
        Read one single unsigned byte from the buffer.
        Specified by:
        readUnsignedByte in interface DataInput
        Returns:
        the unsigned byte as int.
        Throws:
        java.io.IOException - when there are no bytes to read or when the underlying buffer has already been closed.
      • peekUnsignedByte

        public int peekUnsignedByte​(int offset)
                             throws java.io.IOException
        Peeks one single unsigned byte from the buffer.
        Specified by:
        peekUnsignedByte in interface DataInput
        Parameters:
        offset - offset to the byte to be peeked, must be 0 ≤ offset.
        Returns:
        the unsigned byte as int.
        Throws:
        java.io.IOException - when the offset is negative or beyond end_of_buffer or when the underlying buffer has been closed already.
      • readBytes

        public byte[] readBytes​(int length)
                         throws java.io.IOException
        Read a number of single byte values from the buffer.
        Note: when readBytes(5) is called, but there are only 3 bytes available, the caller gets an IOException, not the 3 bytes!
        Specified by:
        readBytes in interface DataInput
        Parameters:
        length - the number of bytes to be read, must be 0 ≤ length.
        Returns:
        an array with containing the bytes from the buffer.
        Throws:
        java.io.IOException - when there are less than length bytes available or when the underlying buffer has already been closed.
      • length

        public int length()
                   throws java.io.IOException
        Specified by:
        length in interface DataInput
        Throws:
        java.io.IOException