Class PDStream

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected PDStream()
      This will create a new empty PDStream object.
        PDStream​(COSStream str)
      Creates a PDStream which wraps the given COSStream.
        PDStream​(PDDocument document)
      This will create a new empty PDStream object.
        PDStream​(PDDocument doc, java.io.InputStream str)
      Constructor.
        PDStream​(PDDocument doc, java.io.InputStream str, boolean filtered)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCompression()
      If there are not compression filters on the current stream then this will add a compression filter, flate compression for example.
      static PDStream createFromCOS​(COSBase base)
      Create a pd stream from either a regular COSStream on a COSArray of cos streams.
      java.io.InputStream createInputStream()
      This will get a stream that can be read from.
      java.io.OutputStream createOutputStream()
      This will get a stream that can be written to.
      byte[] getByteArray()
      This will copy the stream into a byte array.
      COSBase getCOSObject()
      Convert this standard java object to a COS object.
      int getDecodedStreamLength()
      Get the decoded stream length.
      java.util.List<java.lang.Object> getDecodeParms()
      Get the list of decode parameters.
      PDFileSpecification getFile()
      This will get the file specification for this stream.
      java.util.List<java.lang.Object> getFileDecodeParams()
      Get the list of decode parameters.
      java.util.List<java.lang.String> getFileFilters()
      This will get the list of filters that are associated with this stream.
      java.util.List<COSName> getFilters()
      This will get the list of filters that are associated with this stream.
      java.lang.String getInputStreamAsString()
      A convenience method to get this stream as a string.
      int getLength()
      This will get the length of the filtered/compressed stream.
      PDMetadata getMetadata()
      Get the metadata that is part of the document catalog.
      java.io.InputStream getPartiallyFilteredStream​(java.util.List<java.lang.String> stopFilters)
      This will get a stream with some filters applied but not others.
      COSStream getStream()
      Get the cos stream associated with this object.
      void setDecodedStreamLength​(int decodedStreamLength)
      Set the decoded stream length.
      void setDecodeParms​(java.util.List<?> decodeParams)
      This will set the list of decode parameterss.
      void setFile​(PDFileSpecification f)
      Set the file specification.
      void setFileDecodeParams​(java.util.List<?> decodeParams)
      This will set the list of decode params.
      void setFileFilters​(java.util.List<java.lang.String> filters)
      This will set the filters that are part of this stream.
      void setFilters​(java.util.List<COSName> filters)
      This will set the filters that are part of this stream.
      void setMetadata​(PDMetadata meta)
      Set the metadata for this object.
      • Methods inherited from class java.lang.Object

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

      • PDStream

        protected PDStream()
        This will create a new empty PDStream object.
      • PDStream

        public PDStream​(PDDocument document)
        This will create a new empty PDStream object.
        Parameters:
        document - The document that the stream will be part of.
      • PDStream

        public PDStream​(COSStream str)
        Creates a PDStream which wraps the given COSStream.
        Parameters:
        str - The stream parameter.
      • PDStream

        public PDStream​(PDDocument doc,
                        java.io.InputStream str)
                 throws java.io.IOException
        Constructor. Reads all data from the input stream and embeds it into the document, this will close the InputStream.
        Parameters:
        doc - The document that will hold the stream.
        str - The stream parameter.
        Throws:
        java.io.IOException - If there is an error creating the stream in the document.
      • PDStream

        public PDStream​(PDDocument doc,
                        java.io.InputStream str,
                        boolean filtered)
                 throws java.io.IOException
        Constructor. Reads all data from the input stream and embeds it into the document, this will close the InputStream.
        Parameters:
        doc - The document that will hold the stream.
        str - The stream parameter.
        filtered - True if the stream already has a filter applied.
        Throws:
        java.io.IOException - If there is an error creating the stream in the document.
    • Method Detail

      • addCompression

        public void addCompression()
        If there are not compression filters on the current stream then this will add a compression filter, flate compression for example.
      • createFromCOS

        public static PDStream createFromCOS​(COSBase base)
                                      throws java.io.IOException
        Create a pd stream from either a regular COSStream on a COSArray of cos streams.
        Parameters:
        base - Either a COSStream or COSArray.
        Returns:
        A PDStream or null if base is null.
        Throws:
        java.io.IOException - If there is an error creating the PDStream.
      • getCOSObject

        public COSBase getCOSObject()
        Convert this standard java object to a COS object.
        Specified by:
        getCOSObject in interface COSObjectable
        Returns:
        The cos object that matches this Java object.
      • createOutputStream

        public java.io.OutputStream createOutputStream()
                                                throws java.io.IOException
        This will get a stream that can be written to.
        Returns:
        An output stream to write data to.
        Throws:
        java.io.IOException - If an IO error occurs during writing.
      • createInputStream

        public java.io.InputStream createInputStream()
                                              throws java.io.IOException
        This will get a stream that can be read from.
        Returns:
        An input stream that can be read from.
        Throws:
        java.io.IOException - If an IO error occurs during reading.
      • getPartiallyFilteredStream

        public java.io.InputStream getPartiallyFilteredStream​(java.util.List<java.lang.String> stopFilters)
                                                       throws java.io.IOException
        This will get a stream with some filters applied but not others. This is useful when doing images, ie filters = [flate,dct], we want to remove flate but leave dct
        Parameters:
        stopFilters - A list of filters to stop decoding at.
        Returns:
        A stream with decoded data.
        Throws:
        java.io.IOException - If there is an error processing the stream.
      • getStream

        public COSStream getStream()
        Get the cos stream associated with this object.
        Returns:
        The cos object that matches this Java object.
      • getLength

        public int getLength()
        This will get the length of the filtered/compressed stream. This is readonly in the PD Model and will be managed by this class.
        Returns:
        The length of the filtered stream.
      • getFilters

        public java.util.List<COSName> getFilters()
        This will get the list of filters that are associated with this stream. Or null if there are none.
        Returns:
        A list of all encoding filters to apply to this stream.
      • setFilters

        public void setFilters​(java.util.List<COSName> filters)
        This will set the filters that are part of this stream.
        Parameters:
        filters - The filters that are part of this stream.
      • getDecodeParms

        public java.util.List<java.lang.Object> getDecodeParms()
                                                        throws java.io.IOException
        Get the list of decode parameters. Each entry in the list will refer to an entry in the filters list.
        Returns:
        The list of decode parameters.
        Throws:
        java.io.IOException - if there is an error retrieving the parameters.
      • setDecodeParms

        public void setDecodeParms​(java.util.List<?> decodeParams)
        This will set the list of decode parameterss.
        Parameters:
        decodeParams - The list of decode parameterss.
      • getFile

        public PDFileSpecification getFile()
                                    throws java.io.IOException
        This will get the file specification for this stream. This is only required for external files.
        Returns:
        The file specification.
        Throws:
        java.io.IOException - If there is an error creating the file spec.
      • setFile

        public void setFile​(PDFileSpecification f)
        Set the file specification.
        Parameters:
        f - The file specification.
      • getFileFilters

        public java.util.List<java.lang.String> getFileFilters()
        This will get the list of filters that are associated with this stream. Or null if there are none.
        Returns:
        A list of all encoding filters to apply to this stream.
      • setFileFilters

        public void setFileFilters​(java.util.List<java.lang.String> filters)
        This will set the filters that are part of this stream.
        Parameters:
        filters - The filters that are part of this stream.
      • getFileDecodeParams

        public java.util.List<java.lang.Object> getFileDecodeParams()
                                                             throws java.io.IOException
        Get the list of decode parameters. Each entry in the list will refer to an entry in the filters list.
        Returns:
        The list of decode parameters.
        Throws:
        java.io.IOException - if there is an error retrieving the parameters.
      • setFileDecodeParams

        public void setFileDecodeParams​(java.util.List<?> decodeParams)
        This will set the list of decode params.
        Parameters:
        decodeParams - The list of decode params.
      • getByteArray

        public byte[] getByteArray()
                            throws java.io.IOException
        This will copy the stream into a byte array.
        Returns:
        The byte array of the filteredStream
        Throws:
        java.io.IOException - When getFilteredStream did not work
      • getInputStreamAsString

        public java.lang.String getInputStreamAsString()
                                                throws java.io.IOException
        A convenience method to get this stream as a string. Uses the default system encoding.
        Returns:
        a String representation of this (input) stream.
        Throws:
        java.io.IOException - if there is an error while converting the stream to a string.
      • getMetadata

        public PDMetadata getMetadata()
        Get the metadata that is part of the document catalog. This will return null if there is no meta data for this object.
        Returns:
        The metadata for this object.
        Throws:
        java.lang.IllegalStateException - if the value of the metadata entry is different from a stream or null
      • setMetadata

        public void setMetadata​(PDMetadata meta)
        Set the metadata for this object. This can be null.
        Parameters:
        meta - The meta data for this object.
      • getDecodedStreamLength

        public int getDecodedStreamLength()
        Get the decoded stream length.
        Returns:
        the decoded stream length
        Since:
        Apache PDFBox 1.1.0
        See Also:
        PDFBOX-636
      • setDecodedStreamLength

        public void setDecodedStreamLength​(int decodedStreamLength)
        Set the decoded stream length.
        Parameters:
        decodedStreamLength - the decoded stream length
        Since:
        Apache PDFBox 1.1.0
        See Also:
        PDFBOX-636