org.foray.pdf.object
Class PDFStream

java.lang.Object
  extended by org.foray.pdf.object.PDFObject
      extended by org.foray.pdf.object.PDFStream
Direct Known Subclasses:
PDFCMap, PDFContentStream, PDFEmbeddedFileStream, PDFFontFileStream, PDFICCStream, PDFXObject

public abstract class PDFStream
extends PDFObject

Superclass for all PDF stream objects. A PDF Stream has two parts: a dictionary, and the stream itself. The stream of commands is where the real work is done, the dictionary just provides information like the stream length.

See Also:
"PDF Reference, 3rd Edition, Section 3.2.7."

Field Summary
 
Fields inherited from class org.foray.pdf.object.PDFObject
EOL, MSG_EOL, XREF_EOL
 
Constructor Summary
PDFStream(PDFDocument doc)
          Constructor.
 
Method Summary
 void add(String s)
          Append data to the stream.
 void addDefaultFilters()
          Adds the default filter to this stream.
 void addEncryption(PDFEncryption encryption)
          Add the encryption filter.
 void addFilter(org.axsl.ps.PsEncodeFilter filter)
          Add a filter for compression of the stream.
 org.axsl.ps.PsEncodeFilter addFilter(String filterType)
          Adds a filter of the specified type to this stream.
protected  String applyFilters()
          Apply the filters to the data in the order given.
protected abstract  void finalizeStreamContent()
          This method is an explicit opportunity for subclasses to finish writing whatever content may still need to be written to the stream before the dictionary and stream contents are written.
 int getDataLength()
          Returns the number of bytes written to this stream.
protected  OutputStream getOutputStream()
          Returns the output stream.
protected  int output(OutputStream stream)
          Write the PDF represention of this object to a given output stream.
protected  int outputStreamData(OutputStream stream)
          Output just the stream data enclosed by stream/endstream markers.
 void setData(byte[] data)
          Writes some data to this stream.
protected  void setOutputStream(OutputStream outputStream)
          Sets the output stream.
protected abstract  String specialStreamDictEntries()
          Subclasses return any specialized dictionary entries here, so that they are included when writing the stream dictionary.
 String toPDF()
          Generates the PDF text necessary to represent the object, returning it as a String.
 
Methods inherited from class org.foray.pdf.object.PDFObject
bufferToByteArray, byteArrayToStream, getCharsPerLine, getGeneration, getLogger, getNumber, getPDFDocument, pdfID, pdfReference, setNumber, stringToByteArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFStream

public PDFStream(PDFDocument doc)
Constructor. Creates an empty stream object.

Parameters:
doc - The PDFDocument to which this stream is attached.
Method Detail

add

public void add(String s)
         throws org.axsl.pdf.PdfException
Append data to the stream.

Parameters:
s - The string of PDF to add.
Throws:
org.axsl.pdf.PdfException - For errors writing to output.

addFilter

public void addFilter(org.axsl.ps.PsEncodeFilter filter)
               throws org.axsl.pdf.PdfException
Add a filter for compression of the stream. Note that the filters should be added in reverse order, that is the last filter to be applied should be added first. The filter addes should always be a new instance of that filter class. The applied flag in the filter is marked true after it has been applied to the data.

Parameters:
filter - The filter to be added.
Throws:
org.axsl.pdf.PdfException - For errors adding the filter.

addEncryption

public void addEncryption(PDFEncryption encryption)
Add the encryption filter.

Parameters:
encryption - The encryption filter to add.

addFilter

public org.axsl.ps.PsEncodeFilter addFilter(String filterType)
                                     throws org.axsl.pdf.PdfException
Adds a filter of the specified type to this stream. Note that the filters should be added in reverse order, that is the last filter to be applied should be added first.

Parameters:
filterType - The type of filter to add, one of "flate", "ascii-85", or "ascii-hex".
Returns:
The newly-created filter.
Throws:
org.axsl.pdf.PdfException - For errors while adding the filter.

addDefaultFilters

public void addDefaultFilters()
                       throws org.axsl.pdf.PdfException
Adds the default filter to this stream.

Throws:
org.axsl.pdf.PdfException - For errors while adding the filters.

setData

public void setData(byte[] data)
             throws org.axsl.pdf.PdfException
Writes some data to this stream.

Parameters:
data - The data to be written.
Throws:
org.axsl.pdf.PdfException - For errors when writing.

getDataLength

public int getDataLength()
Returns the number of bytes written to this stream.

Returns:
The number of bytes written to this stream.

toPDF

public String toPDF()
Description copied from class: PDFObject
Generates the PDF text necessary to represent the object, returning it as a String.

Returns:
The PDF text necessary to represent the object.

output

protected int output(OutputStream stream)
              throws org.axsl.pdf.PdfException
Description copied from class: PDFObject
Write the PDF represention of this object to a given output stream.

Overrides:
output in class PDFObject
Parameters:
stream - The stream to which the PDF content is being written.
Returns:
The number of bytes written.
Throws:
org.axsl.pdf.PdfException - For I/O errors during output.

finalizeStreamContent

protected abstract void finalizeStreamContent()
                                       throws org.axsl.pdf.PdfException
This method is an explicit opportunity for subclasses to finish writing whatever content may still need to be written to the stream before the dictionary and stream contents are written.

Throws:
org.axsl.pdf.PdfException - For errors writing stream content.

specialStreamDictEntries

protected abstract String specialStreamDictEntries()
                                            throws org.axsl.pdf.PdfException
Subclasses return any specialized dictionary entries here, so that they are included when writing the stream dictionary.

Returns:
Any specialized dictionary entries.
Throws:
org.axsl.pdf.PdfException - For errors creating the dictionary entries.

outputStreamData

protected int outputStreamData(OutputStream stream)
                        throws org.axsl.pdf.PdfException
Output just the stream data enclosed by stream/endstream markers.

Parameters:
stream - The stream to which the data should be written.
Returns:
The number of bytes written.
Throws:
org.axsl.pdf.PdfException - For errors during writing.

applyFilters

protected String applyFilters()
Apply the filters to the data in the order given.

Returns:
The /Filter and /DecodeParms entries for the stream dictionary.

getOutputStream

protected OutputStream getOutputStream()
Returns the output stream.

Returns:
The output stream.

setOutputStream

protected void setOutputStream(OutputStream outputStream)
Sets the output stream.

Parameters:
outputStream - The new output stream.


Copyright © 2017. All rights reserved.