org.apache.pdfbox.cos
Class COSStream

java.lang.Object
  extended by org.apache.pdfbox.cos.COSBase
      extended by org.apache.pdfbox.cos.COSDictionary
          extended by org.apache.pdfbox.cos.COSStream
All Implemented Interfaces:
COSObjectable
Direct Known Subclasses:
COSStreamArray

public class COSStream
extends COSDictionary

This class represents a stream object in a PDF document.

Version:
$Revision: 1.41 $
Author:
Ben Litchfield

Field Summary
 
Fields inherited from class org.apache.pdfbox.cos.COSDictionary
items
 
Constructor Summary
COSStream(COSDictionary dictionary, RandomAccess storage)
          Constructor.
COSStream(RandomAccess storage)
          Constructor.
 
Method Summary
 java.lang.Object accept(ICOSVisitor visitor)
          visitor pattern double dispatch method.
 java.io.OutputStream createFilteredStream()
          This will create a new stream for which filtered byte should be written to.
 java.io.OutputStream createFilteredStream(COSBase expectedLength)
          This will create a new stream for which filtered byte should be written to.
 java.io.OutputStream createUnfilteredStream()
          This will create an output stream that can be written to.
 long getFilteredLength()
          This will get the length of the encoded stream.
 java.io.InputStream getFilteredStream()
          This will get the stream with all of the filters applied.
 COSBase getFilters()
          This will return the filters to apply to the byte stream.
 RandomAccess getScratchFile()
          This will get the scratch file associated with this stream.
 java.util.List<java.lang.Object> getStreamTokens()
          This will get all the tokens in the stream.
 java.io.InputStream getUnfilteredStream()
          This will get the logical content stream with none of the filters.
 void replaceWithStream(COSStream stream)
          This will replace this object with the data from the new object.
 void setFilters(COSBase filters)
          set the filters to be applied to the stream.
 
Methods inherited from class org.apache.pdfbox.cos.COSDictionary
addAll, clear, containsKey, containsKey, containsValue, entrySet, getBoolean, getBoolean, getBoolean, getDate, getDate, getDate, getDate, getDictionaryObject, getDictionaryObject, getDictionaryObject, getDictionaryObject, getDictionaryObject, getEmbeddedDate, getEmbeddedDate, getEmbeddedDate, getEmbeddedDate, getEmbeddedInt, getEmbeddedInt, getEmbeddedInt, getEmbeddedInt, getEmbeddedString, getEmbeddedString, getEmbeddedString, getEmbeddedString, getFloat, getFloat, getFloat, getFloat, getInt, getInt, getInt, getInt, getInt, getInt, getInt, getItem, getItem, getKeyForValue, getLong, getLong, getLong, getLong, getLong, getNameAsString, getNameAsString, getNameAsString, getNameAsString, getObjectFromPath, getString, getString, getString, getString, getValues, keyList, keySet, mergeInto, removeItem, setBoolean, setBoolean, setDate, setDate, setEmbeddedDate, setEmbeddedDate, setEmbeddedInt, setEmbeddedInt, setEmbeddedString, setEmbeddedString, setFloat, setFloat, setInt, setInt, setItem, setItem, setItem, setItem, setLong, setLong, setName, setName, setString, setString, size, toString
 
Methods inherited from class org.apache.pdfbox.cos.COSBase
getCOSObject, getFilterManager, isDirect, isNeedToBeUpdate, setDirect, setNeedToBeUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

COSStream

public COSStream(RandomAccess storage)
Constructor. Creates a new stream with an empty dictionary.

Parameters:
storage - The intermediate storage for the stream.

COSStream

public COSStream(COSDictionary dictionary,
                 RandomAccess storage)
Constructor.

Parameters:
dictionary - The dictionary that is associated with this stream.
storage - The intermediate storage for the stream.
Method Detail

replaceWithStream

public void replaceWithStream(COSStream stream)
This will replace this object with the data from the new object. This is used to easily maintain referential integrity when changing references to new objects.

Parameters:
stream - The stream that have the new values in it.

getScratchFile

public RandomAccess getScratchFile()
This will get the scratch file associated with this stream.

Returns:
The scratch file where this stream is being stored.

getStreamTokens

public java.util.List<java.lang.Object> getStreamTokens()
                                                 throws java.io.IOException
This will get all the tokens in the stream.

Returns:
All of the tokens in the stream.
Throws:
java.io.IOException - If there is an error parsing the stream.

getFilteredStream

public java.io.InputStream getFilteredStream()
                                      throws java.io.IOException
This will get the stream with all of the filters applied.

Returns:
the bytes of the physical (endoced) stream
Throws:
java.io.IOException - when encoding/decoding causes an exception

getFilteredLength

public long getFilteredLength()
                       throws java.io.IOException
This will get the length of the encoded stream.

Returns:
the length of the encoded stream as long
Throws:
java.io.IOException

getUnfilteredStream

public java.io.InputStream getUnfilteredStream()
                                        throws java.io.IOException
This will get the logical content stream with none of the filters.

Returns:
the bytes of the logical (decoded) stream
Throws:
java.io.IOException - when encoding/decoding causes an exception

accept

public java.lang.Object accept(ICOSVisitor visitor)
                        throws COSVisitorException
visitor pattern double dispatch method.

Overrides:
accept in class COSDictionary
Parameters:
visitor - The object to notify when visiting this object.
Returns:
any object, depending on the visitor implementation, or null
Throws:
COSVisitorException - If an error occurs while visiting this object.

getFilters

public COSBase getFilters()
This will return the filters to apply to the byte stream. The method will return - null if no filters are to be applied - a COSName if one filter is to be applied - a COSArray containing COSNames if multiple filters are to be applied

Returns:
the COSBase object representing the filters

createFilteredStream

public java.io.OutputStream createFilteredStream()
                                          throws java.io.IOException
This will create a new stream for which filtered byte should be written to. You probably don't want this but want to use the createUnfilteredStream, which is used to write raw bytes to.

Returns:
A stream that can be written to.
Throws:
java.io.IOException - If there is an error creating the stream.

createFilteredStream

public java.io.OutputStream createFilteredStream(COSBase expectedLength)
                                          throws java.io.IOException
This will create a new stream for which filtered byte should be written to. You probably don't want this but want to use the createUnfilteredStream, which is used to write raw bytes to.

Parameters:
expectedLength - An entry where a length is expected.
Returns:
A stream that can be written to.
Throws:
java.io.IOException - If there is an error creating the stream.

setFilters

public void setFilters(COSBase filters)
                throws java.io.IOException
set the filters to be applied to the stream.

Parameters:
filters - The filters to set on this stream.
Throws:
java.io.IOException - If there is an error clearing the old filters.

createUnfilteredStream

public java.io.OutputStream createUnfilteredStream()
                                            throws java.io.IOException
This will create an output stream that can be written to.

Returns:
An output stream which raw data bytes should be written to.
Throws:
java.io.IOException - If there is an error creating the stream.