Class PdfStream


public class PdfStream extends PdfDictionary
Representation of a stream as described in the PDF Specification.
  • Field Details

    • compressionLevel

      protected int compressionLevel
    • outputStream

      protected PdfOutputStream outputStream
  • Constructor Details

    • PdfStream

      public PdfStream (byte[] bytes, int compressionLevel)
      Constructs a PdfStream-object.
      Parameters:
      bytes - initial content of PdfOutputStream.
      compressionLevel - the compression level (0 = best speed, 9 = best compression, -1 is default)
    • PdfStream

      public PdfStream (byte[] bytes)
      Creates a PdfStream instance.
      Parameters:
      bytes - bytes to write to the PdfStream
    • PdfStream

      public PdfStream (PdfDocument doc, InputStream inputStream, int compressionLevel)
      Creates an efficient stream. No temporary array is ever created. The InputStream is totally consumed but is not closed. The general usage is:
       PdfDocument document = ?;
       InputStream in = ?;
       PdfStream stream = new PdfStream(document, in, PdfOutputStream.DEFAULT_COMPRESSION);
       ?
       stream.flush();
       in.close();
       
      Parameters:
      doc - the pdf document in which this stream lies
      inputStream - the data to write to this stream
      compressionLevel - the compression level (0 = best speed, 9 = best compression, -1 is default)
    • PdfStream

      public PdfStream (PdfDocument doc, InputStream inputStream)
      Creates an efficient stream. No temporary array is ever created. The InputStream is totally consumed but is not closed. The general usage is:
       PdfDocument document = ?;
       InputStream in = ?;
       PdfStream stream = new PdfStream(document, in);
       stream.flush();
       in.close();
       
      Parameters:
      doc - the pdf document in which this stream lies
      inputStream - the data to write to this stream
    • PdfStream

      public PdfStream (int compressionLevel)
      Constructs a PdfStream-object.
      Parameters:
      compressionLevel - the compression level (0 = best speed, 9 = best compression, -1 is default)
    • PdfStream

      public PdfStream()
      Creates an empty PdfStream instance.
    • PdfStream

      protected PdfStream (OutputStream outputStream)
  • Method Details

    • getOutputStream

      public PdfOutputStream getOutputStream()
      Gets output stream.
      Returns:
      output stream
    • getCompressionLevel

      public int getCompressionLevel()
      Gets compression level of this PdfStream. For more details @see DeflaterOutputStream.
      Returns:
      compression level.
    • setCompressionLevel

      public void setCompressionLevel (int compressionLevel)
      Sets compression level of this PdfStream. For more details @see DeflaterOutputStream.
      Parameters:
      compressionLevel - the compression level (0 = best speed, 9 = best compression, -1 is default)
    • getType

      public byte getType()
      Description copied from class: PdfObject
      Gets object type.
      Overrides:
      getType in class PdfDictionary
      Returns:
      object type.
    • getLength

      public int getLength()
    • getBytes

      public byte[] getBytes()
      Gets decoded stream bytes. Note, PdfName.DCTDecode and PdfName.JPXDecode filters will be ignored.
      Returns:
      byte content of the PdfStream. Byte content will be null, if the PdfStream was created by InputStream.
    • getBytes

      public byte[] getBytes (boolean decoded)
      Gets stream bytes. Note, PdfName.DCTDecode and PdfName.JPXDecode filters will be ignored.
      Parameters:
      decoded - true if to get decoded stream bytes, otherwise false.
      Returns:
      byte content of the PdfStream. Byte content will be null, if the PdfStream was created by InputStream.
    • setData

      public void setData (byte[] bytes)
      Sets bytes as stream's content. Could not be used with streams which were created by InputStream.
      Parameters:
      bytes - new content for stream; if null then stream's content will be discarded
    • setData

      public void setData (byte[] bytes, boolean append)
      Sets or appends bytes to stream content. Could not be used with streams which were created by InputStream.
      Parameters:
      bytes - New content for stream. These bytes are considered to be a raw data (i.e. not encoded/compressed/encrypted) and if it's not true, the corresponding filters shall be set to the PdfStream object manually. Data compression generally should be configured via setCompressionLevel(int) and is handled on stream writing to the output document. If null and append is false then stream's content will be discarded.
      append - If set to true then bytes will be appended to the end, rather then replace original content. The original content will be decoded if needed.
    • newInstance

      protected PdfObject newInstance()
      Description copied from class: PdfObject
      Creates new instance of object.
      Overrides:
      newInstance in class PdfDictionary
      Returns:
      new instance of object.
    • getOffset

      protected long getOffset()
    • updateLength

      protected void updateLength (int length)
      Update length manually in case its correction.
      Parameters:
      length - the new length
      See Also:
      • PdfReader.checkPdfStreamLength(PdfStream)
    • copyContent

      protected void copyContent (PdfObject from, PdfDocument document)
      Description copied from class: PdfDictionary
      Copies object content from object 'from'.
      Overrides:
      copyContent in class PdfDictionary
      Parameters:
      from - object to copy content from.
      document - document to copy object to.
    • copyContent

      protected void copyContent (PdfObject from, PdfDocument document, ICopyFilter copyFilter)
      Description copied from class: PdfDictionary
      Copies object content from object 'from'.
      Overrides:
      copyContent in class PdfDictionary
      Parameters:
      from - object to copy content from.
      document - document to copy object to.
      copyFilter - ICopyFilter a filter that will apply on dictionaries and array Use NullCopyFilter for no filtering
    • initOutputStream

      protected void initOutputStream (OutputStream stream)
    • releaseContent

      protected void releaseContent()
      Release content of PdfStream.
      Overrides:
      releaseContent in class PdfDictionary
    • getInputStream

      protected InputStream getInputStream()