Interface Stream

  • All Superinterfaces:
    java.lang.AutoCloseable
    All Known Implementing Classes:
    FileStream, MemoryStream

    public interface Stream
    extends java.lang.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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close()
      Close the stream and release all associated resources.
      long getLength()
      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 tell()
      Get current byte position
      void write​(byte[] buffer, int offset, int length)
      Write to the stream
    • Method Detail

      • getLength

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

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

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

        int read​(byte[] buffer,
                 int offset,
                 int length)
          throws java.io.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:
        java.io.IOException
      • write

        void write​(byte[] buffer,
                   int offset,
                   int length)
            throws java.io.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:
        java.io.IOException
      • close

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