Class RandomAccessSource

java.lang.Object
org.apache.pdfbox.pdfparser.RandomAccessSource
All Implemented Interfaces:
Closeable, AutoCloseable, SequentialSource

final class RandomAccessSource extends Object implements SequentialSource
A SequentialSource backed by a RandomAccessRead.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final RandomAccessRead
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    long
    Returns offset of next byte to be returned by a read method.
    boolean
    Returns true if the end of the data source has been reached.
    int
    This will peek at the next byte.
    int
    Read a single byte of data.
    int
    read(byte[] b)
    Read a buffer of data.
    int
    read(byte[] b, int offset, int length)
    Read a buffer of data.
    byte[]
    readFully(int length)
    Reads a given number of bytes in its entirety.
    void
    unread(byte[] bytes)
    Unreads an array of bytes.
    void
    unread(byte[] bytes, int start, int len)
    Unreads a portion of an array of bytes.
    void
    unread(int b)
    Unreads a single byte.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RandomAccessSource

      RandomAccessSource(RandomAccessRead reader)
      Constructor.
      Parameters:
      reader - The random access reader to wrap.
  • Method Details

    • read

      public int read() throws IOException
      Description copied from interface: SequentialSource
      Read a single byte of data.
      Specified by:
      read in interface SequentialSource
      Returns:
      The byte of data that is being read.
      Throws:
      IOException - If there is an error while reading the data.
    • read

      public int read(byte[] b) throws IOException
      Description copied from interface: SequentialSource
      Read a buffer of data.
      Specified by:
      read in interface SequentialSource
      Parameters:
      b - The buffer to write the data to.
      Returns:
      The number of bytes that were actually read.
      Throws:
      IOException - If there was an error while reading the data.
    • read

      public int read(byte[] b, int offset, int length) throws IOException
      Description copied from interface: SequentialSource
      Read a buffer of data.
      Specified by:
      read in interface SequentialSource
      Parameters:
      b - The buffer to write the data to.
      offset - Offset into the buffer to start writing.
      length - The amount of data to attempt to read.
      Returns:
      The number of bytes that were actually read.
      Throws:
      IOException - If there was an error while reading the data.
    • getPosition

      public long getPosition() throws IOException
      Description copied from interface: SequentialSource
      Returns offset of next byte to be returned by a read method.
      Specified by:
      getPosition in interface SequentialSource
      Returns:
      offset of next byte which will be returned with next SequentialSource.read() (if no more bytes are left it returns a value >= length of source).
      Throws:
      IOException - If there was an error while reading the data.
    • peek

      public int peek() throws IOException
      Description copied from interface: SequentialSource
      This will peek at the next byte.
      Specified by:
      peek in interface SequentialSource
      Returns:
      The next byte on the stream, leaving it as available to read.
      Throws:
      IOException - If there is an error reading the next byte.
    • unread

      public void unread(int b) throws IOException
      Description copied from interface: SequentialSource
      Unreads a single byte.
      Specified by:
      unread in interface SequentialSource
      Parameters:
      b - byte array to push back
      Throws:
      IOException - if there is an error while unreading
    • unread

      public void unread(byte[] bytes) throws IOException
      Description copied from interface: SequentialSource
      Unreads an array of bytes.
      Specified by:
      unread in interface SequentialSource
      Parameters:
      bytes - byte array to be unread
      Throws:
      IOException - if there is an error while unreading
    • unread

      public void unread(byte[] bytes, int start, int len) throws IOException
      Description copied from interface: SequentialSource
      Unreads a portion of an array of bytes.
      Specified by:
      unread in interface SequentialSource
      Parameters:
      bytes - byte array to be unread
      start - start index
      len - number of bytes to be unread
      Throws:
      IOException - if there is an error while unreading
    • readFully

      public byte[] readFully(int length) throws IOException
      Description copied from interface: SequentialSource
      Reads a given number of bytes in its entirety.
      Specified by:
      readFully in interface SequentialSource
      Parameters:
      length - the number of bytes to be read
      Returns:
      a byte array containing the bytes just read
      Throws:
      IOException - if an I/O error occurs while reading data
    • isEOF

      public boolean isEOF() throws IOException
      Description copied from interface: SequentialSource
      Returns true if the end of the data source has been reached.
      Specified by:
      isEOF in interface SequentialSource
      Returns:
      true if we are at the end of the data.
      Throws:
      IOException - If there is an error reading the next byte.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException