Class DocumentOutputStream

  • All Implemented Interfaces:
    DocumentOutput

    public class DocumentOutputStream
    extends java.lang.Object
    implements DocumentOutput
    A streamed output for Engine results. This work only for monolithic file formats. Not support are: The Java, HTML, SVG and the old XLS format. Also PDF with fastwebview=true or signature. A typical usage is:
     
     Engine eng = new Engine( Engine.EXPORT_PDF );
     eng.setReportFile( "myReport.rpt" );
     eng.setDocumentLocation( new DocumentOutputStream( new FileOutputStream( "myReport.pdf" ), true ) );
     eng.execute() 
     
     
    Since:
    16.2
    • Constructor Summary

      Constructors 
      Constructor Description
      DocumentOutputStream​(java.io.OutputStream output, boolean autoClose)
      Create a new streamed output for a Engine.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFontData​(byte[] fontData)
      Add the data for an embedded font.
      void addPage​(byte[] page)
      Add a page/chunk.
      void clear()
      Reset this output in the initial state.
      int getFontCount()
      Get the count of added fonts.
      byte[] getFontData​(int idx)
      Get the font data from the given index.
      byte[] getGroupTree()
      Get the data of the group tree.
      int getPageCount()
      Get the current count of pages.
      byte[] getPageData​(int idx)
      Get the binary data of a page/chunk.
      boolean isPageLimitExceeded()
      Check if the rendering of the report ran into a page limit.
      void setErrorData​(byte[] error)
      Set error data.
      void setFontData​(byte[] fontData, int idx)
      Override the font data with a new version.
      void setGroupTree​(byte[] data)
      Set the group tree.
      void setPageData​(byte[] page, int idx)
      Override/patched an existing page/chunk.
      void setPageLimitExceeded()
      Set that a PageLimitException exception occur.
      void setUsingTotalPage()
      Set that a total page is used in the report.
      void stop​(java.lang.String cause)
      The rendering was stopped.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DocumentOutputStream

        public DocumentOutputStream​(java.io.OutputStream output,
                                    boolean autoClose)
        Create a new streamed output for a Engine. This does not work for all output formats.
        Parameters:
        output - the target output
        autoClose - if the stream should be close on finish or error.
        Since:
        16.2
    • Method Detail

      • getPageCount

        public int getPageCount()
        Get the current count of pages.
        Specified by:
        getPageCount in interface DocumentOutput
        Returns:
        the page count
      • clear

        public void clear()
        Reset this output in the initial state. So getPageCount() == 0 and getFontCount() == 0.
        Specified by:
        clear in interface DocumentOutput
      • getPageData

        public byte[] getPageData​(int idx)
                           throws java.lang.ArrayIndexOutOfBoundsException
        Get the binary data of a page/chunk.
        Specified by:
        getPageData in interface DocumentOutput
        Parameters:
        idx - the index, starts with 1
        Returns:
        the data, never null
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if index is out of range
      • getGroupTree

        public byte[] getGroupTree()
        Get the data of the group tree.
        Specified by:
        getGroupTree in interface DocumentOutput
        Returns:
        Can be null, if not set.
      • addPage

        public void addPage​(byte[] page)
                     throws java.lang.IllegalStateException
        Add a page/chunk. Increment DocumentOutput.getPageCount()
        Specified by:
        addPage in interface DocumentOutput
        Parameters:
        page - the binary data, never null
        Throws:
        java.lang.IllegalStateException - if this output is finish or stopped.
      • setPageData

        public void setPageData​(byte[] page,
                                int idx)
                         throws java.lang.IllegalStateException
        Override/patched an existing page/chunk.
        Specified by:
        setPageData in interface DocumentOutput
        Parameters:
        page - die binary data, never null
        idx - the index, starts with 1
        Throws:
        java.lang.IllegalStateException - if this output is finish or stopped.
      • setGroupTree

        public void setGroupTree​(byte[] data)
                          throws java.lang.IllegalStateException
        Set the group tree. After this call this output is finish and any try to change this object should throw an exception. This call does not change DocumentOutput.getPageCount().
        Specified by:
        setGroupTree in interface DocumentOutput
        Parameters:
        data - the binary data, never null, but can be an empty array
        Throws:
        java.lang.IllegalStateException - if this output is finish or stopped.
      • setErrorData

        public void setErrorData​(byte[] error)
                          throws java.lang.IllegalStateException
        Set error data. After this call this output is finish and any try to change this object should throw an exception.
        Specified by:
        setErrorData in interface DocumentOutput
        Parameters:
        error - serialized Exception
        Throws:
        java.lang.IllegalStateException - if this output is finish or stopped.
      • stop

        public void stop​(java.lang.String cause)
        The rendering was stopped. This is called from Engine.stop(). After this call any try to change this object should throw an exception.
        Specified by:
        stop in interface DocumentOutput
        Parameters:
        cause - an optional message
      • addFontData

        public void addFontData​(byte[] fontData)
                         throws java.lang.IllegalStateException
        Add the data for an embedded font. Increment DocumentOutput.getFontCount(). This method is only used from the Java/C# output format.
        Specified by:
        addFontData in interface DocumentOutput
        Parameters:
        fontData - binary data in the current protocol format.
        Throws:
        java.lang.IllegalStateException - if this output is finish or stopped.
      • setFontData

        public void setFontData​(byte[] fontData,
                                int idx)
                         throws java.lang.IllegalStateException
        Override the font data with a new version.
        Specified by:
        setFontData in interface DocumentOutput
        Parameters:
        fontData - binary data in the current protocol format.
        idx - the index, starts with 0
        Throws:
        java.lang.IllegalStateException - if this output is finish or stopped.
      • getFontData

        public byte[] getFontData​(int idx)
                           throws java.lang.ArrayIndexOutOfBoundsException
        Get the font data from the given index.
        Specified by:
        getFontData in interface DocumentOutput
        Parameters:
        idx - the index, starts with 0
        Returns:
        the font data, never null
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if index is out of range
      • getFontCount

        public int getFontCount()
        Get the count of added fonts.
        Specified by:
        getFontCount in interface DocumentOutput
        Returns:
        the font count
      • setPageLimitExceeded

        public void setPageLimitExceeded()
        Set that a PageLimitException exception occur.
        Specified by:
        setPageLimitExceeded in interface DocumentOutput
      • isPageLimitExceeded

        public boolean isPageLimitExceeded()
        Check if the rendering of the report ran into a page limit. This means does not all possible pages exist.
        Specified by:
        isPageLimitExceeded in interface DocumentOutput
        Returns:
        true, if PageLimitException was occur
      • setUsingTotalPage

        public void setUsingTotalPage()
        Set that a total page is used in the report.
        Specified by:
        setUsingTotalPage in interface DocumentOutput