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

org.apache.fop.afp

## Class DataStream

- java.lang.Object
- - org.apache.fop.afp.DataStream

-     public class DataStream
      extends Object

  A data stream is a continuous ordered stream of data elements and objects conforming to a given format. Application programs can generate data streams destined for a presentation service, archive library, presentation device or another application program. The strategic presentation data stream architectures used is Mixed Object Document Content Architecture (MO:DCA). The MO:DCA architecture defines the data stream used by applications to describe documents and object envelopes for interchange with other applications and application services. Documents defined in the MO:DCA format may be archived in a database, then later retrieved, viewed, annotated and printed in local or distributed systems environments. Presentation fidelity is accommodated by including resource objects in the documents that reference them.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static org.apache.commons.logging.Log` | `LOG` Static logging instance

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataStream(Factory factory, AFPPaintingState paintingState, OutputStream outputStream)` Default constructor for the AFPDocumentStream.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addFontsToCurrentPage(Map pageFonts)` Creates the given page fonts in the current page
    `void` | `createFont(int fontReference, AFPFont font, int size)` Helper method to create a map coded font object on the current page, this method delegates the construction of the map coded font object to the active environment group on the current page.
    `void` | `createIncludePageOverlay(String name, int x, int y)` Helper method which allows creation of the MPO object, via the AEG.
    `void` | `createIncludePageSegment(String name, int x, int y, int width, int height)` Creates an IncludePageSegment on the current page.
    `void` | `createInvokeMediumMap(String name)` Helper method which allows creation of the IMM object.
    `void` | `createLine(AFPLineDataInfo lineDataInfo)` Method to create a line on the current page.
    `void` | `createNoOperation(String content)` Creates a NoOperation item
    `void` | `createPageGroupTagLogicalElement(TagLogicalElement.State[] attributes)` Creates a TagLogicalElement on the current page group.
    `void` | `createPageTagLogicalElement(TagLogicalElement.State[] attributes)` Creates a TagLogicalElement on the current page.
    `void` | `createShading(int x, int y, int w, int h, Color col)` This method will create shading on the page using the specified coordinates (the shading contrast is controlled via the red, green, blue parameters, by converting this to grey scale).
    `void` | `createTagLogicalElement(String name, String value, int encoding)` Creates a TagLogicalElement on the current page or page group
    `void` | `createText(AFPTextDataInfo textDataInfo, int letterSpacing, int wordSpacing, Font font, CharacterSet charSet)` Helper method to create text on the current page, this method delegates to the current presentation text object in order to construct the text.
    `void` | `endDocument()` Helper method to mark the end of the current document.
    `void` | `endOverlay()` Helper method to mark the end of the current overlay.
    `void` | `endPage()` Helper method to mark the end of the current page.
    `void` | `endPageGroup(boolean endPageGroup)` Helper method to mark the end of the page group.
    `AbstractPageObject` | `getCurrentPage()` Returns the current page
    `PageGroup` | `getCurrentPageGroup()` Returns the current page group
    `InterchangeSet` | `getInterchangeSet()` Returns the MO:DCA interchange set in use
    `OutputStream` | `getOutputStream()` Returns the outputstream
    `ResourceGroup` | `getResourceGroup(AFPResourceLevel level)` Returns the resource group for a given resource info
    `void` | `restorePage(PageObject pageObject)` Helper method to restore the current page.
    `PageObject` | `savePage()` Helper method to save the current page.
    `void` | `setDocumentName(String name)` The document is started by invoking this method which creates an instance of the AFP Document object.
    `void` | `setInterchangeSet(InterchangeSet interchangeSet)` Sets the MO:DCA interchange set to use
    `void` | `startDocument()` Start a new document.
    `void` | `startOverlay(int x, int y, int width, int height, int widthRes, int heightRes, int overlayRotation)` Start a new overlay.
    `void` | `startPage(int pageWidth, int pageHeight, int pageRotation, int pageWidthRes, int pageHeightRes)` Start a new page.
    `void` | `startPageGroup(boolean endPageGroup)` Start a new page group.

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

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

- - ### Field Detail

    - #### LOG

          protected static final org.apache.commons.logging.Log LOG

      Static logging instance

  - ### Constructor Detail

    - #### DataStream

          public DataStream(Factory factory,
                            AFPPaintingState paintingState,
                            OutputStream outputStream)

      Default constructor for the AFPDocumentStream.
      Parameters:
        `factory` - the resource factory
        `paintingState` - the AFP painting state
        `outputStream` - the outputstream to write to

  - ### Method Detail

    - #### getOutputStream

          public OutputStream getOutputStream()

      Returns the outputstream
      Returns:
        the outputstream

    - #### getCurrentPage

          public AbstractPageObject getCurrentPage()

      Returns the current page
      Returns:
        the current page

    - #### setDocumentName

          public void setDocumentName(String name)

      The document is started by invoking this method which creates an instance of the AFP Document object.
      Parameters:
        `name` - the name of this document.

    - #### endDocument

          public void endDocument()
                           throws IOException

      Helper method to mark the end of the current document.
      Throws:
        `IOException` - thrown if an I/O exception of some sort has occurred

    - #### startPage

          public void startPage(int pageWidth,
                                int pageHeight,
                                int pageRotation,
                                int pageWidthRes,
                                int pageHeightRes)

      Start a new page. When processing has finished on the current page, the `endPage()`method must be invoked to mark the page ending.
      Parameters:
        `pageWidth` - the width of the page
        `pageHeight` - the height of the page
        `pageRotation` - the rotation of the page
        `pageWidthRes` - the width resolution of the page
        `pageHeightRes` - the height resolution of the page

    - #### startOverlay

          public void startOverlay(int x,
                                   int y,
                                   int width,
                                   int height,
                                   int widthRes,
                                   int heightRes,
                                   int overlayRotation)

      Start a new overlay. When processing has finished on the current overlay, the `endOverlay()`method must be invoked to mark the overlay ending.
      Parameters:
        `x` - the x position of the overlay on the page
        `y` - the y position of the overlay on the page
        `width` - the width of the overlay
        `height` - the height of the overlay
        `widthRes` - the width resolution of the overlay
        `heightRes` - the height resolution of the overlay
        `overlayRotation` - the rotation of the overlay

    - #### endOverlay

          public void endOverlay()
                          throws IOException

      Helper method to mark the end of the current overlay.
      Throws:
        `IOException` - thrown if an I/O exception of some sort has occurred

    - #### savePage

          public PageObject savePage()

      Helper method to save the current page.
      Returns:
        current page object that was saved

    - #### restorePage

          public void restorePage(PageObject pageObject)

      Helper method to restore the current page.
      Parameters:
        `pageObject` - page object

    - #### endPage

          public void endPage()
                       throws IOException

      Helper method to mark the end of the current page.
      Throws:
        `IOException` - thrown if an I/O exception of some sort has occurred

    - #### addFontsToCurrentPage

          public void addFontsToCurrentPage(Map pageFonts)

      Creates the given page fonts in the current page
      Parameters:
        `pageFonts` - a collection of AFP font attributes

    - #### createFont

          public void createFont(int fontReference,
                                 AFPFont font,
                                 int size)

      Helper method to create a map coded font object on the current page, this method delegates the construction of the map coded font object to the active environment group on the current page.
      Parameters:
        `fontReference` - the font number used as the resource identifier
        `font` - the font
        `size` - the point size of the font

    - #### createText

          public void createText(AFPTextDataInfo textDataInfo,
                                 int letterSpacing,
                                 int wordSpacing,
                                 Font font,
                                 CharacterSet charSet)
                          throws UnsupportedEncodingException

      Helper method to create text on the current page, this method delegates to the current presentation text object in order to construct the text.
      Parameters:
        `textDataInfo` - the afp text data
        `letterSpacing` - letter spacing to draw text with
        `wordSpacing` - word Spacing to draw text with
        `font` - is the font to draw text with
        `charSet` - is the AFP Character Set to use with the text
      Throws:
        `UnsupportedEncodingException` - thrown if character encoding is not supported

    - #### createLine

          public void createLine(AFPLineDataInfo lineDataInfo)

      Method to create a line on the current page.
      Parameters:
        `lineDataInfo` - the line data information.

    - #### createShading

          public void createShading(int x,
                                    int y,
                                    int w,
                                    int h,
                                    Color col)

      This method will create shading on the page using the specified coordinates (the shading contrast is controlled via the red, green, blue parameters, by converting this to grey scale).
      Parameters:
        `x` - the x coordinate of the shading
        `y` - the y coordinate of the shading
        `w` - the width of the shaded area
        `h` - the height of the shaded area
        `col` - the shading color

    - #### createIncludePageOverlay

          public void createIncludePageOverlay(String name,
                                               int x,
                                               int y)

      Helper method which allows creation of the MPO object, via the AEG. And the IPO via the Page. (See actual object for descriptions.)
      Parameters:
        `name` - the name of the static overlay
        `x` - x-coordinate
        `y` - y-coordinate

    - #### createInvokeMediumMap

          public void createInvokeMediumMap(String name)

      Helper method which allows creation of the IMM object.
      Parameters:
        `name` - the name of the medium map

    - #### createIncludePageSegment

          public void createIncludePageSegment(String name,
                                               int x,
                                               int y,
                                               int width,
                                               int height)

      Creates an IncludePageSegment on the current page.
      Parameters:
        `name` - the name of the include page segment
        `x` - the x coordinate for the overlay
        `y` - the y coordinate for the overlay
        `width` - the width of the image
        `height` - the height of the image

    - #### createPageTagLogicalElement

          public void createPageTagLogicalElement(TagLogicalElement.State[] attributes)

      Creates a TagLogicalElement on the current page.
      Parameters:
        `attributes` - the array of key value pairs.

    - #### createPageGroupTagLogicalElement

          public void createPageGroupTagLogicalElement(TagLogicalElement.State[] attributes)

      Creates a TagLogicalElement on the current page group.
      Parameters:
        `attributes` - the array of key value pairs.

    - #### createTagLogicalElement

          public void createTagLogicalElement(String name,
                                              String value,
                                              int encoding)

      Creates a TagLogicalElement on the current page or page group
      Parameters:
        `name` - The tag name
        `value` - The tag value
        `encoding` - The CCSID character set encoding

    - #### createNoOperation

          public void createNoOperation(String content)

      Creates a NoOperation item
      Parameters:
        `content` - byte data

    - #### getCurrentPageGroup

          public PageGroup getCurrentPageGroup()

      Returns the current page group
      Returns:
        the current page group

    - #### startDocument

          public void startDocument()
                             throws IOException

      Start a new document.
      Throws:
        `IOException` - thrown if an I/O exception of some sort has occurred

    - #### startPageGroup

          public void startPageGroup(boolean endPageGroup)
                              throws IOException

      Start a new page group. When processing has finished on the current page group the endPageGroup method must be invoked to mark the page group ending.
      Throws:
        `IOException` - thrown if an I/O exception of some sort has occurred

    - #### endPageGroup

          public void endPageGroup(boolean endPageGroup)
                            throws IOException

      Helper method to mark the end of the page group.
      Throws:
        `IOException` - thrown if an I/O exception of some sort has occurred

    - #### setInterchangeSet

          public void setInterchangeSet(InterchangeSet interchangeSet)

      Sets the MO:DCA interchange set to use
      Parameters:
        `interchangeSet` - the MO:DCA interchange set

    - #### getInterchangeSet

          public InterchangeSet getInterchangeSet()

      Returns the MO:DCA interchange set in use
      Returns:
        the MO:DCA interchange set in use

    - #### getResourceGroup

          public ResourceGroup getResourceGroup(AFPResourceLevel level)

      Returns the resource group for a given resource info
      Parameters:
        `level` - a resource level
      Returns:
        a resource group for the given resource info

Copyright © 2025 Apache Software Foundation. All rights reserved.