Interface Stream

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
FileStream, MemoryStream

public interface Stream extends AutoCloseable
The unified stream interface for reading and writing data. Java's stream interfaces cannot be used, because they are lacking two important features:
  • The PDF file format is based on random access. Java streams have only limited support for this.
  • The ability to read from an output stream is crucial for processing large PDF files.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the stream and release all associated resources.
    long
    Get the length of the stream in bytes
    int
    read(byte[] buffer, int offset, int length)
    Read from the stream
    boolean
    seek(long position)
    Set byte position
    long
    Get current byte position
    void
    write(byte[] buffer, int offset, int length)
    Write to the stream
  • Method Details

    • getLength

      long getLength() throws IOException
      Get the length of the stream in bytes
      Returns:
      the length of the stream in bytes
      Throws:
      IOException
    • seek

      boolean seek(long position) throws IOException
      Set byte position
      Parameters:
      position - The new position of the stream (-1 for EOS)
      Returns:
      true if successful
      Throws:
      IOException
    • tell

      long tell() throws IOException
      Get current byte position
      Returns:
      byte position, -1 if position unknown
      Throws:
      IOException
    • read

      int read(byte[] buffer, int offset, int length) throws IOException
      Read from the stream
      Parameters:
      buffer - The buffer where the data is written
      offset - The starting element in the buffer
      length - The maximum number of bytes to be read
      Returns:
      The actual number of bytes read (-1 if EOS)
      Throws:
      IOException
    • write

      void write(byte[] buffer, int offset, int length) throws IOException
      Write to the stream
      Parameters:
      buffer - The buffer where the data lies
      offset - The starting element in the buffer
      length - The maximum number of bytes to write
      Throws:
      IOException
    • close

      void close() throws IOException
      Close the stream and release all associated resources.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException