Class PdfStream
- java.lang.Object
-
- com.aowagie.text.pdf.PdfObject
-
- com.aowagie.text.pdf.PdfDictionary
-
- com.aowagie.text.pdf.PdfStream
-
- Direct Known Subclasses:
BaseFont.StreamFont,PdfContents,PdfEFStream,PdfFormXObject,PdfICCBased,PdfImage,PdfPattern,PRStream
public class PdfStream extends PdfDictionary
PdfStreamis the Pdf stream object.A stream, like a string, is a sequence of characters. However, an application can read a small portion of a stream at a time, while a string must be read in its entirety. For this reason, objects with potentially large amounts of data, such as images and page descriptions, are represented as streams.
A stream consists of a dictionary that describes a sequence of characters, followed by the keyword stream, followed by zero or more lines of characters, followed by the keyword endstream.
All streams must bePdfIndirectObjects. The stream dictionary must be a direct object. The keyword stream that follows the stream dictionary should be followed by a carriage return and linefeed or just a linefeed.
Remark: In this version only the FLATEDECODE-filter is supported.
This object is described in the 'Portable Document Format Reference Manual version 1.7' section 3.2.7 (page 60-63).- See Also:
PdfObject,PdfDictionary
-
-
Field Summary
Fields Modifier and Type Field Description static intBEST_COMPRESSIONA possible compression level.protected booleancompressedis the stream compressed?protected intcompressionLevelThe level of compression.static intDEFAULT_COMPRESSIONA possible compression level.(package private) static byte[]ENDSTREAMprotected java.io.InputStreaminputStreamprotected intinputStreamLengthstatic intNO_COMPRESSIONA possible compression level.protected intrawLengthprivate PdfIndirectReferenceref(package private) static byte[]STARTSTREAMprotected java.io.ByteArrayOutputStreamstreamBytesprivate PdfWriterwriter-
Fields inherited from class com.aowagie.text.pdf.PdfDictionary
CATALOG, hashMap, OUTLINES, PAGE
-
Fields inherited from class com.aowagie.text.pdf.PdfObject
ARRAY, BOOLEAN, bytes, DICTIONARY, INDIRECT, NAME, NOTHING, NULL, NUMBER, STREAM, STRING, TEXT_PDFDOCENCODING, TEXT_UNICODE, type
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidflateCompress(int compressionLevel)Compresses the stream.intgetRawLength()Gets the raw length of the stream.protected voidsuperToPdf(PdfWriter writer, java.io.OutputStream os)voidtoPdf(PdfWriter writer, java.io.OutputStream os)Writes the PDF representation of thisPdfDictionaryas an array ofbyteto the givenOutputStream.java.lang.StringtoString()Returns a string representation of thisPdfDictionary.(package private) voidwriteContent(java.io.OutputStream os)Writes the data content to anOutputStream.(package private) voidwriteLength()Writes the stream length to thePdfWriter.-
Methods inherited from class com.aowagie.text.pdf.PdfDictionary
contains, get, getAsArray, getAsBoolean, getAsDict, getAsIndirectObject, getAsName, getAsNumber, getAsString, getDirectObject, getKeys, isCatalog, isFont, isOutlineTree, isPage, isPages, merge, mergeDifferent, put, putAll, remove, size
-
Methods inherited from class com.aowagie.text.pdf.PdfObject
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, setContent, setIndRef, type
-
-
-
-
Field Detail
-
DEFAULT_COMPRESSION
public static final int DEFAULT_COMPRESSION
A possible compression level.- Since:
- 2.1.3
- See Also:
- Constant Field Values
-
NO_COMPRESSION
public static final int NO_COMPRESSION
A possible compression level.- Since:
- 2.1.3
- See Also:
- Constant Field Values
-
BEST_COMPRESSION
public static final int BEST_COMPRESSION
A possible compression level.- Since:
- 2.1.3
- See Also:
- Constant Field Values
-
compressed
protected boolean compressed
is the stream compressed?
-
compressionLevel
protected int compressionLevel
The level of compression.- Since:
- 2.1.3
-
streamBytes
protected java.io.ByteArrayOutputStream streamBytes
-
inputStream
protected java.io.InputStream inputStream
-
ref
private PdfIndirectReference ref
-
inputStreamLength
protected int inputStreamLength
-
writer
private PdfWriter writer
-
rawLength
protected int rawLength
-
STARTSTREAM
static final byte[] STARTSTREAM
-
ENDSTREAM
static final byte[] ENDSTREAM
-
-
Constructor Detail
-
PdfStream
public PdfStream(byte[] bytes)
Constructs aPdfStream-object.- Parameters:
bytes- content of the newPdfObjectas an array ofbyte.
-
PdfStream
PdfStream(java.io.InputStream inputStream, PdfWriter writer)Creates an efficient stream. No temporary array is ever created. TheInputStreamis totally consumed but is not closed. The general usage is:InputStream in = ...; PdfStream stream = new PdfStream(in, writer); stream.flateCompress(); writer.addToBody(stream); stream.writeLength(); in.close();
- Parameters:
inputStream- the data to write to this streamwriter- thePdfWriterfor this stream
-
PdfStream
protected PdfStream()
Constructs aPdfStream-object.
-
-
Method Detail
-
writeLength
void writeLength() throws java.io.IOExceptionWrites the stream length to thePdfWriter.This method must be called and can only be called if the constructor
PdfStream(InputStream,PdfWriter)is used to create the stream.- Throws:
java.io.IOException- on error- See Also:
PdfStream(InputStream,PdfWriter)
-
getRawLength
public int getRawLength()
Gets the raw length of the stream.- Returns:
- the raw length of the stream
-
flateCompress
void flateCompress(int compressionLevel)
Compresses the stream.- Parameters:
compressionLevel- the compression level (0 = best speed, 9 = best compression, -1 is default)- Since:
- 2.1.3
-
superToPdf
protected void superToPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
- Throws:
java.io.IOException
-
toPdf
public void toPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Description copied from class:PdfDictionaryWrites the PDF representation of thisPdfDictionaryas an array ofbyteto the givenOutputStream.- Overrides:
toPdfin classPdfDictionary- Parameters:
writer- for backwards compatibilityos- theOutputStreamto write the bytes to.- Throws:
java.io.IOException- Exception with a I/O error- See Also:
PdfDictionary.toPdf(com.aowagie.text.pdf.PdfWriter, java.io.OutputStream)
-
writeContent
void writeContent(java.io.OutputStream os) throws java.io.IOExceptionWrites the data content to anOutputStream.- Parameters:
os- the destination to write to- Throws:
java.io.IOException- on error
-
toString
public java.lang.String toString()
Description copied from class:PdfDictionaryReturns a string representation of thisPdfDictionary. The string doesn't contain any of the content of this dictionary. Rather the string "dictionary" is returned, possibly followed by the type of thisPdfDictionary, if set.- Overrides:
toStringin classPdfDictionary- Returns:
- the string representation of this
PdfDictionary - See Also:
PdfObject.toString()
-
-