com.lowagie.text.pdf

Class PdfStream

public class PdfStream extends PdfDictionary

PdfStream is 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 be PdfIndirectObjects. 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
static intBEST_COMPRESSION
A possible compression level.
static intBEST_SPEED
A possible compression level.
protected booleancompressed
is the stream compressed?
protected intcompressionLevel
The level of compression.
static intDEFAULT_COMPRESSION
A possible compression level.
static byte[]ENDSTREAM
protected InputStreaminputStream
protected intinputStreamLength
static intNO_COMPRESSION
A possible compression level.
protected intrawLength
protected PdfIndirectReferenceref
protected ByteArrayOutputStreamstreamBytes
static intSIZESTREAM
static byte[]STARTSTREAM
protected PdfWriterwriter
Constructor Summary
PdfStream(byte[] bytes)
Constructs a PdfStream-object.
PdfStream(InputStream inputStream, PdfWriter writer)
Creates an efficient stream.
protected PdfStream()
Constructs a PdfStream-object.
Method Summary
voidflateCompress()
Compresses the stream.
voidflateCompress(int compressionLevel)
Compresses the stream.
intgetRawLength()
Gets the raw length of the stream.
protected voidsuperToPdf(PdfWriter writer, OutputStream os)
voidtoPdf(PdfWriter writer, OutputStream os)
StringtoString()
voidwriteContent(OutputStream os)
Writes the data content to an OutputStream.
voidwriteLength()
Writes the stream length to the PdfWriter.

Field Detail

BEST_COMPRESSION

public static final int BEST_COMPRESSION
A possible compression level.

Since: 2.1.3

BEST_SPEED

public static final int BEST_SPEED
A possible compression level.

Since: 2.1.3

compressed

protected boolean compressed
is the stream compressed?

compressionLevel

protected int compressionLevel
The level of compression.

Since: 2.1.3

DEFAULT_COMPRESSION

public static final int DEFAULT_COMPRESSION
A possible compression level.

Since: 2.1.3

ENDSTREAM

static final byte[] ENDSTREAM

inputStream

protected InputStream inputStream

inputStreamLength

protected int inputStreamLength

NO_COMPRESSION

public static final int NO_COMPRESSION
A possible compression level.

Since: 2.1.3

rawLength

protected int rawLength

ref

protected PdfIndirectReference ref

streamBytes

protected ByteArrayOutputStream streamBytes

SIZESTREAM

static final int SIZESTREAM

STARTSTREAM

static final byte[] STARTSTREAM

writer

protected PdfWriter writer

Constructor Detail

PdfStream

public PdfStream(byte[] bytes)
Constructs a PdfStream-object.

Parameters: bytes content of the new PdfObject as an array of byte.

PdfStream

public PdfStream(InputStream inputStream, PdfWriter writer)
Creates an efficient stream. No temporary array is ever created. The InputStream is 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 stream writer the PdfWriter for this stream

PdfStream

protected PdfStream()
Constructs a PdfStream-object.

Method Detail

flateCompress

public void flateCompress()
Compresses the stream.

flateCompress

public 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

getRawLength

public int getRawLength()
Gets the raw length of the stream.

Returns: the raw length of the stream

superToPdf

protected void superToPdf(PdfWriter writer, OutputStream os)

toPdf

public void toPdf(PdfWriter writer, OutputStream os)

See Also: PdfDictionary

toString

public String toString()

See Also: toString

writeContent

public void writeContent(OutputStream os)
Writes the data content to an OutputStream.

Parameters: os the destination to write to

Throws: IOException on error

writeLength

public void writeLength()
Writes the stream length to the PdfWriter.

This method must be called and can only be called if the constructor PdfStream is used to create the stream.

Throws: IOException on error

See Also: PdfStream