AbstractPDFStream (Apache FOP Core 2.11 API)
Date: 2025-04-24

org.apache.fop.pdf

## Class AbstractPDFStream

- java.lang.Object
- - org.apache.fop.pdf.PDFObject
  - - org.apache.fop.pdf.AbstractPDFStream

- All Implemented Interfaces:
    PDFWritable
  Direct Known Subclasses:
    AbstractPDFFontStream, PDFStream, PDFXObject

      public abstract class AbstractPDFStream
      extends PDFObject

  This is an abstract base class for PDF streams.

- - ### Field Summary

    - ### Fields inherited from class org.apache.fop.pdf.PDFObject

      `log`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractPDFStream()`
    `protected` | `AbstractPDFStream(boolean encodeOnTheFly)`
    `protected` | `AbstractPDFStream(PDFDictionary dictionary)`
    `protected` | `AbstractPDFStream(PDFDictionary dictionary, boolean encodeOnTheFly)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected int` | `encodeAndWriteStream(OutputStream out, PDFNumber refLength)` Encodes and writes a stream directly to an OutputStream.
    `protected StreamCache` | `encodeStream()` Encodes the raw data stream for output to a PDF file.
    `Object` | `get(String key)`
    `void` | `getChildren(Set<PDFObject> children)`
    `protected String` | `getDefaultFilterName()` Returns the name of a suitable filter for this PDF object.
    `protected PDFDictionary` | `getDictionary()`
    `PDFFilterList` | `getFilterList()` Returns the associated filter list.
    `protected abstract int` | `getSizeHint()` Returns a value that hints at the size of the encoded stream.
    `protected boolean` | `multipleFiltersAllowed()` Whether multiple filters can be applied.
    `int` | `output(OutputStream stream)` Overload the base object method so we don't have to copy byte arrays around so much Write the PDF represention of this object
    `protected abstract void` | `outputRawStreamData(OutputStream out)` Sends the raw stream data to the target OutputStream.
    `protected int` | `outputStreamData(StreamCache encodedStream, OutputStream out)` Output just the stream data enclosed by stream/endstream markers
    `protected void` | `populateStreamDict(Object lengthEntry)` Populates the dictionary with all necessary entries for the stream.
    `protected void` | `prepareImplicitFilters()` Prepares implicit filters (such as the DCTFilter for JPEG images).
    `void` | `put(String key, Object value)` Puts the given object in the dictionary associated to this stream.
    `void` | `registerChildren()`
    `void` | `setDocument(PDFDocument doc)` Sets the parent PDFDocument.
    `protected void` | `setupFilterList()` Sets up the default filters for this stream if they haven't been set from outside.
    `boolean` | `supportsObjectStream()`

    - ### Methods inherited from class org.apache.fop.pdf.PDFObject

      `contentEquals, encode, encodeBinaryToHexString, encodeString, encodeText, formatObject, getDocument, getDocumentSafely, getGeneration, getObjectID, getObjectNumber, getParent, hasObjectNumber, makeReference, outputInline, referencePDF, setObjectNumber, setObjectNumber, setObjectNumber, setParent, toPDF, toPDFString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AbstractPDFStream

          protected AbstractPDFStream()

    - #### AbstractPDFStream

          protected AbstractPDFStream(PDFDictionary dictionary)

    - #### AbstractPDFStream

          protected AbstractPDFStream(boolean encodeOnTheFly)

    - #### AbstractPDFStream

          protected AbstractPDFStream(PDFDictionary dictionary,
                                      boolean encodeOnTheFly)

  - ### Method Detail

    - #### getDictionary

          protected final PDFDictionary getDictionary()

    - #### get

          public Object get(String key)

    - #### put

          public void put(String key,
                          Object value)

      Puts the given object in the dictionary associated to this stream.
      Parameters:
        `key` - the key in the dictionary
        `value` - the value to store

    - #### setupFilterList

          protected void setupFilterList()

      Sets up the default filters for this stream if they haven't been set from outside.

    - #### getDefaultFilterName

          protected String getDefaultFilterName()

      Returns the name of a suitable filter for this PDF object.
      Returns:
        the default filter
      See Also:
        `PDFFilterList`

    - #### getFilterList

          public PDFFilterList getFilterList()

      Returns the associated filter list.
      Returns:
        the filter list

    - #### getSizeHint

          protected abstract 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.
      Returns:
        an estimated size (0 if no hint can be given)
      Throws:
        `IOException` - in case of an I/O problem

    - #### outputRawStreamData

          protected abstract void outputRawStreamData(OutputStream out)
                                               throws IOException

      Sends the raw stream data to the target OutputStream.
      Parameters:
        `out` - OutputStream to write to
      Throws:
        `IOException` - In case of an I/O problem

    - #### outputStreamData

          protected int outputStreamData(StreamCache encodedStream,
                                         OutputStream out)
                                  throws IOException

      Output just the stream data enclosed by stream/endstream markers
      Parameters:
        `encodedStream` - already encoded/filtered stream to write
        `out` - OutputStream to write to
      Returns:
        int number of bytes written
      Throws:
        `IOException` - in case of an I/O problem

    - #### encodeStream

          protected StreamCache encodeStream()
                                      throws IOException

      Encodes the raw data stream for output to a PDF file.
      Returns:
        the encoded stream
      Throws:
        `IOException` - in case of an I/O problem

    - #### encodeAndWriteStream

          protected int encodeAndWriteStream(OutputStream out,
                                             PDFNumber refLength)
                                      throws IOException

      Encodes and writes a stream directly to an OutputStream. The length of the stream, in this case, is set on a PDFNumber object that has to be prepared beforehand.
      Parameters:
        `out` - OutputStream to write to
        `refLength` - PDFNumber object to receive the stream length
      Returns:
        number of bytes written (header and trailer included)
      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 `PDFObject`
      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

    - #### setDocument

          public void setDocument(PDFDocument doc)

      Description copied from class: `PDFObject`
      Sets the parent PDFDocument.
      Overrides:
        `setDocument` in class `PDFObject`
      Parameters:
        `doc` - the PDFDocument.

    - #### populateStreamDict

          protected void populateStreamDict(Object lengthEntry)

      Populates the dictionary with all necessary entries for the stream. Override this method if you need additional entries.
      Parameters:
        `lengthEntry` - value for the /Length entry

    - #### prepareImplicitFilters

          protected void prepareImplicitFilters()

      Prepares implicit filters (such as the DCTFilter for JPEG images). You must make sure that the appropriate filters are in the filter list at the right places.

    - #### multipleFiltersAllowed

          protected boolean multipleFiltersAllowed()

      Whether multiple filters can be applied.
      Returns:
        true if multiple filters allowed

    - #### getChildren

          public void getChildren(Set<PDFObject> children)

      Overrides:
        `getChildren` in class `PDFObject`

    - #### registerChildren

          public void registerChildren()

    - #### supportsObjectStream

          public boolean supportsObjectStream()

      Overrides:
        `supportsObjectStream` in class `PDFObject`

Copyright © 2025 Apache Software Foundation. All rights reserved.