intarsys PDF library API

de.intarsys.pdf.cos
Class COSStream

java.lang.Object
  extended by de.intarsys.pdf.cos.COSDocumentElement
      extended by de.intarsys.pdf.cos.COSObject
          extended by de.intarsys.pdf.cos.COSCompositeObject
              extended by de.intarsys.pdf.cos.COSStream
All Implemented Interfaces:
ICOSContainer, ICOSExceptionHandler, IAttributeSupport, de.intarsys.tools.component.ISaveStateSupport

public class COSStream
extends COSCompositeObject

An object representing stream data in a PDF document. Unlike a string, stream data is not restricted in length. Stream data may be encoded with the filter implementation.


Field Summary
static COSName DK_DecodeParms
           
static COSName DK_DP
           
static COSName DK_F
           
static COSName DK_FDecodeParams
           
static COSName DK_FFilter
           
static COSName DK_Filter
           
static COSName DK_Length
           
static COSName DK_Resources
           
static Object SLOT_BYTES
           
 
Fields inherited from class de.intarsys.pdf.cos.COSObject
CONSTANT_CONTAINER, NULL_CONTAINER, SLOT_CONTAINER
 
Method Summary
 Object accept(ICOSObjectVisitor visitor)
          Accept a visitor object.
 void addFilter(COSName name)
          Add a new filter to this.
 void addObjectListener(ICOSObjectListener listener)
          Add a listener for object changes.
 COSStream asStream()
           
 Iterator basicIterator()
          An iterator over contained objects and references.
 void basicSetDecodedBytes(byte[] newBytes)
          Set the streams logical content.
 void basicSetEncodedBytes(byte[] newBytes)
          Set the streams physical content.
 COSStream copyDecodeFirst()
          A copy of this, bytes decoded.
 COSObject copyDeep(Map copied)
          Make a deep copy of the receiver within the same document.
 COSObject copyShallow()
          Make a copy of the receiver.
static COSStream create(COSDictionary dict)
          Create a new COSStream.
 int getAnyLength()
          The declared or real length for this.
 byte[] getDecodedBytes()
          The unfiltered (logical) stream content.
 byte[] getDecodedBytesWritable()
          The unfiltered content as in getDecodedBytes, but allow the caller to manipulate the result by copying/not caching the returned bytes
 COSObject getDecodeParams()
          The options or an array of options for filtering.
static COSObject getDecodeParams(COSDictionary dict)
          The options or an array of options for filtering.
static COSDictionary getDecodeParams(COSDictionary dict, COSName name)
          The options corresponding to the first occurence of the filter name.
 COSObject getDecodeParams(COSName name)
          The options corresponding to the first occurence of the filter name.
 COSDictionary getDict()
          The stream dictionary
 byte[] getEncodedBytes()
          The filtered (physical) stream content.
 COSObject getFilters()
          Return the filter or the collection of filters for the stream.
static COSObject getFilters(COSDictionary dict)
          Return the filter or the collection of filters for the stream.
 COSDictionary getFirstDecodeParam()
          A dictionary with filter options or the first element of an array of such dictionaries for each filter.
 COSName getFirstFilter()
          The filter or the first element of the collection of filters for the stream.
 int getLength()
          The length of the filtered content
static boolean hasFilter(COSDictionary dict, COSName name)
          true if the stream hs declared a filter name.
 boolean hasFilter(COSName name)
          true if the stream hs declared a filter name.
 boolean isExternal()
          true if the stream dictionary contains the F key.
static boolean isExternal(COSDictionary dict)
          true if the stream dictionary contains the F key.
 Iterator iterator()
          An iterator over contained objects.
 void removeFilters()
          Remove all filters from this.
 void removeObjectListener(ICOSObjectListener listener)
          Remove a listener for object changes.
 void restoreState(Object object)
           
 Object saveState()
           
 void setDecodedBytes(byte[] newBytes)
          Set the streams logical content
 void setEncodedBytes(byte[] newBytes)
          Set the stream physical content.
 
Methods inherited from class de.intarsys.pdf.cos.COSCompositeObject
associate, containable, copyDeep, disassociate, getAttribute, isObjectListenerAvailable, isPrimitive, referenceCount, referenceIndirect, register, removeAttribute, restoreStateContainer, saveStateContainer, setAttribute, willChange
 
Methods inherited from class de.intarsys.pdf.cos.COSObject
asArray, asBoolean, asDictionary, asFixed, asInteger, asName, asNull, asNumber, asString, beConstant, beIndirect, containable, copyOptional, copySubGraph, dereference, getContainer, getDoc, getIndirectObject, isDangling, isIndirect, isNull, isNumber, isSwapped, stringValue, toString
 
Methods inherited from class de.intarsys.pdf.cos.COSDocumentElement
handleException, isReference
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.intarsys.pdf.cos.ICOSContainer
getDoc
 

Field Detail

SLOT_BYTES

public static final Object SLOT_BYTES

DK_DecodeParms

public static final COSName DK_DecodeParms

DK_DP

public static final COSName DK_DP

DK_F

public static final COSName DK_F

DK_FDecodeParams

public static final COSName DK_FDecodeParams

DK_FFilter

public static final COSName DK_FFilter

DK_Filter

public static final COSName DK_Filter

DK_Length

public static final COSName DK_Length

DK_Resources

public static final COSName DK_Resources
Method Detail

create

public static COSStream create(COSDictionary dict)
Create a new COSStream.

Parameters:
dict - An optional dictionary to be used as the streams dictionary.
Returns:
Create a new COSStream.

getDecodeParams

public static COSObject getDecodeParams(COSDictionary dict)
The options or an array of options for filtering.

Returns:
The options or an array of options for filtering.

getDecodeParams

public static COSDictionary getDecodeParams(COSDictionary dict,
                                            COSName name)
The options corresponding to the first occurence of the filter name.

Returns:
The options corresponding to the first occurence of the filter name.

getFilters

public static COSObject getFilters(COSDictionary dict)
Return the filter or the collection of filters for the stream.

Returns:
The filter or the collection of filters for the stream.

hasFilter

public static boolean hasFilter(COSDictionary dict,
                                COSName name)
true if the stream hs declared a filter name.

Parameters:
name - The name of the filter.
Returns:
true if the stream hs declared a filter name.

isExternal

public static boolean isExternal(COSDictionary dict)
true if the stream dictionary contains the F key.

Returns:
true if the stream dictionary contains the F key.

accept

public Object accept(ICOSObjectVisitor visitor)
              throws COSVisitorException
Description copied from class: COSDocumentElement
Accept a visitor object. The receiver selects the correct implementation in the visitor by "double dispatching".

Specified by:
accept in class COSDocumentElement
Parameters:
visitor - The object visiting the receiver.
Returns:
Object An object depending on the visitor semantics.
Throws:
COSVisitorException - An exception depending on the visitor semantics.

addFilter

public void addFilter(COSName name)
Add a new filter to this.

Parameters:
name - The logical naem of the filter.

addObjectListener

public void addObjectListener(ICOSObjectListener listener)
Description copied from class: COSObject
Add a listener for object changes.

Overrides:
addObjectListener in class COSCompositeObject
Parameters:
listener - The listener to be informed about changes.

asStream

public COSStream asStream()
Overrides:
asStream in class COSObject
Returns:
a COSStream or null

basicIterator

public Iterator basicIterator()
Description copied from class: COSObject
An iterator over contained objects and references. The iterator is an empty iterator if this is not a container.

This iterator returns COSDocumentElements, leaving references alone.

Specified by:
basicIterator in class COSObject
Returns:
Iterator over contained objects and references.

basicSetDecodedBytes

public void basicSetDecodedBytes(byte[] newBytes)
Set the streams logical content.

Parameters:
newBytes - the logical content for the stream

basicSetEncodedBytes

public void basicSetEncodedBytes(byte[] newBytes)
Set the streams physical content.

Parameters:
newBytes - the physical content for the stream

copyDecodeFirst

public COSStream copyDecodeFirst()
                          throws IOException
A copy of this, bytes decoded.

Returns:
A copy of this, bytes decoded.
Throws:
IOException

copyDeep

public COSObject copyDeep(Map copied)
Description copied from class: COSObject
Make a deep copy of the receiver within the same document. The result is a "PDF semantic" deep copy, implementation artifacts as "attributes" and listeners are NOT copied.

The copied map is used to identify objects copied in earlier runs of this method to avoid duplicating resources used in different copy targets (for example the pages of a document). copied is modified while executing copyDeep and contains a mapping from indirect objects in the original document to copied objects.

The algorithm copies this along with all outgoing references (recursively).

Object identity is preserved.

Be careful when copying objects, as there are semantics that may NOT be recognized by this method.

Overrides:
copyDeep in class COSCompositeObject
Returns:
the object copied recursively
See Also:
COSObject.copyDeep()

copyShallow

public COSObject copyShallow()
Description copied from class: COSObject
Make a copy of the receiver.

A copy is made of the receiver and after this recursively of all not indirect objects.

Be careful when copying objects, as there are semantics that may NOT be recognized by this method.

Overrides:
copyShallow in class COSObject
Returns:
The object copied

getAnyLength

public int getAnyLength()
The declared or real length for this.

Returns:
The declared or real length for this.

getDecodedBytes

public byte[] getDecodedBytes()
The unfiltered (logical) stream content. It is not intended to manipulate the byte array directly.

Returns:
The unfiltered (logical) stream content
Throws:
IOException

getDecodedBytesWritable

public byte[] getDecodedBytesWritable()
The unfiltered content as in getDecodedBytes, but allow the caller to manipulate the result by copying/not caching the returned bytes

Returns:
The unfiltered content as in getDecodedBytes

getDecodeParams

public COSObject getDecodeParams()
The options or an array of options for filtering.

Returns:
The options or an array of options for filtering.

getDecodeParams

public COSObject getDecodeParams(COSName name)
The options corresponding to the first occurence of the filter name.

Returns:
The options corresponding to the first occurence of the filter name.

getDict

public COSDictionary getDict()
The stream dictionary

Returns:
The stream dictionary

getEncodedBytes

public byte[] getEncodedBytes()
The filtered (physical) stream content. If it must be generated first, then the content length is adjusted as a side effect. It is not intended to manipulate the byte array directly.

Returns:
The filtered (physical) stream content

getFilters

public COSObject getFilters()
Return the filter or the collection of filters for the stream.

Returns:
The filter or the collection of filters for the stream.

getFirstDecodeParam

public COSDictionary getFirstDecodeParam()
A dictionary with filter options or the first element of an array of such dictionaries for each filter.

Returns:
A dictionary with filter options or the first element of an array of such dictionaries for each filter.

getFirstFilter

public COSName getFirstFilter()
The filter or the first element of the collection of filters for the stream.

Returns:
The filter or the first element of the collection of filters for the stream.

getLength

public int getLength()
The length of the filtered content

Returns:
The length of the filtered content

hasFilter

public boolean hasFilter(COSName name)
true if the stream hs declared a filter name.

Parameters:
name - The name of the filter.
Returns:
true if the stream hs declared a filter name.

isExternal

public boolean isExternal()
true if the stream dictionary contains the F key.

Returns:
true if the stream dictionary contains the F key.

iterator

public Iterator iterator()
Description copied from class: COSObject
An iterator over contained objects. The iterator is an empty iterator if this is not a container.

This iterator returns only COSObject instances, references are dereferenced.

Specified by:
iterator in class COSObject
Returns:
Iterator over contained objects.

removeFilters

public void removeFilters()
Remove all filters from this.


removeObjectListener

public void removeObjectListener(ICOSObjectListener listener)
Description copied from class: COSObject
Remove a listener for object changes.

Overrides:
removeObjectListener in class COSCompositeObject
Parameters:
listener - The listener to be removed.

restoreState

public void restoreState(Object object)
Specified by:
restoreState in interface de.intarsys.tools.component.ISaveStateSupport
Overrides:
restoreState in class COSObject

saveState

public Object saveState()

setDecodedBytes

public void setDecodedBytes(byte[] newBytes)
Set the streams logical content

Parameters:
newBytes - The logical content for the stream

setEncodedBytes

public void setEncodedBytes(byte[] newBytes)
Set the stream physical content.

Parameters:
newBytes - the physical content for the stream

intarsys PDF library API

Copyright © 2006 intarsys consulting GmbH. All Rights Reserved.