Class PDFStream

All Implemented Interfaces:
PDFWritable
Direct Known Subclasses:
ObjectStream, PDFCMap, PDFEmbeddedFile, PDFICCStream, PDFMetadata

public class PDFStream extends AbstractPDFStream
Class representing a PDF stream.

A derivative of the PDF Object, a PDF Stream has not only a dictionary but a stream of PDF commands. The stream of commands is where the real work is done, the dictionary just provides information like the stream length.

  • Field Details

    • data

      protected StreamCache data
      The stream of PDF commands
  • Constructor Details

    • PDFStream

      public PDFStream()
      Create an empty stream object
    • PDFStream

      public PDFStream(PDFDictionary dictionary)
    • PDFStream

      public PDFStream(PDFDictionary dictionary, boolean encodeOnTheFly)
    • PDFStream

      public PDFStream(boolean encodeOnTheFly)
  • Method Details

    • add

      public void add(String s)
      Append data to the stream
      Parameters:
      s - the string of PDF to add
    • add

      public void add(StringBuffer sb)
      Append data to the stream
      Parameters:
      sb - the string buffer of PDF to add
    • getBufferWriter

      public Writer getBufferWriter()
      Returns a Writer that writes to the OutputStream of the buffer.
      Returns:
      the Writer
    • getBufferOutputStream

      public OutputStream getBufferOutputStream() throws IOException
      Returns an OutputStream that can be used to write to the buffer which is used to build up the PDF stream.
      Returns:
      the OutputStream
      Throws:
      IOException - In case of an I/O problem
    • setData

      public void setData(byte[] data) throws IOException
      Used to set the contents of the PDF stream.
      Parameters:
      data - the contents as a byte array
      Throws:
      IOException - in case of an I/O problem
    • getDataLength

      public int getDataLength()
      Returns the size of the content.
      Returns:
      size of the content
    • getSizeHint

      protected int getSizeHint() throws IOException
      Returns a value that hints at the size of the encoded stream. This is used to optimize buffer allocation so fewer buffer reallocations are necessary.
      Specified by:
      getSizeHint in class AbstractPDFStream
      Returns:
      an estimated size (0 if no hint can be given)
      Throws:
      IOException - in case of an I/O problem
    • outputRawStreamData

      protected void outputRawStreamData(OutputStream out) throws IOException
      Sends the raw stream data to the target OutputStream.
      Specified by:
      outputRawStreamData in class AbstractPDFStream
      Parameters:
      out - OutputStream to write to
      Throws:
      IOException - In case of an I/O problem
    • output

      public int output(OutputStream stream) throws IOException
      Overload the base object method so we don't have to copy byte arrays around so much Write the PDF represention of this object
      Overrides:
      output in class AbstractPDFStream
      Parameters:
      stream - the stream to write the PDF to
      Returns:
      the number of bytes written
      Throws:
      IOException - if there is an error writing to the stream
    • streamHashCode

      public String streamHashCode() throws IOException
      Throws:
      IOException