This class represents a stream object in a PDF document.
Method from org.apache.pdfbox.cos.COSStream Detail: |
public Object accept(ICOSVisitor visitor) throws COSVisitorException {
return visitor.visitFromStream(this);
}
visitor pattern double dispatch method. |
public OutputStream createFilteredStream() throws IOException {
filteredStream = new RandomAccessFileOutputStream( file );
unFilteredStream = null;
return new BufferedOutputStream( filteredStream, BUFFER_SIZE );
}
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. |
public OutputStream createFilteredStream(COSBase expectedLength) throws IOException {
filteredStream = new RandomAccessFileOutputStream( file );
filteredStream.setExpectedLength( expectedLength );
unFilteredStream = null;
return new BufferedOutputStream( filteredStream, BUFFER_SIZE );
}
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. |
public OutputStream createUnfilteredStream() throws IOException {
unFilteredStream = new RandomAccessFileOutputStream( file );
filteredStream = null;
return new BufferedOutputStream( unFilteredStream, BUFFER_SIZE );
}
This will create an output stream that can be written to. |
public InputStream getFilteredStream() throws IOException {
if( filteredStream == null )
{
doEncode();
}
long position = filteredStream.getPosition();
long length = filteredStream.getLength();
RandomAccessFileInputStream input =
new RandomAccessFileInputStream( file, position, length );
return new BufferedInputStream( input, BUFFER_SIZE );
}
This will get the stream with all of the filters applied. |
public COSBase getFilters() {
return getDictionaryObject(COSName.FILTER);
}
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 |
public RandomAccess getScratchFile() {
return file;
}
This will get the scratch file associated with this stream. |
public List<Object> getStreamTokens() throws IOException {
PDFStreamParser parser = new PDFStreamParser( this );
parser.parse();
return parser.getTokens();
}
This will get all the tokens in the stream. |
public InputStream getUnfilteredStream() throws IOException {
InputStream retval = null;
if( unFilteredStream == null )
{
doDecode();
}
//if unFilteredStream is still null then this stream has not been
//created yet, so we should return null.
if( unFilteredStream != null )
{
long position = unFilteredStream.getPosition();
long length = unFilteredStream.getLength();
RandomAccessFileInputStream input =
new RandomAccessFileInputStream( file, position, length );
retval = new BufferedInputStream( input, BUFFER_SIZE );
}
else
{
// We should check if the COSStream contains data, maybe it
// has been created with a RandomAccessFile - which is not
// necessary empty.
// In this case, the creation was been done as an input, this should
// be the unfiltered file, since no filter has been applied yet.
// if ( (file != null) &&
// (file.length() > 0) )
// {
// retval = new RandomAccessFileInputStream( file,
// 0,
// file.length() );
// }
// else
// {
//if there is no stream data then simply return an empty stream.
retval = new ByteArrayInputStream( new byte[0] );
// }
}
return retval;
}
This will get the logical content stream with none of the filters. |
public void replaceWithStream(COSStream stream) {
this.clear();
this.addAll( stream );
file = stream.file;
filteredStream = stream.filteredStream;
unFilteredStream = stream.unFilteredStream;
}
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. |
public void setFilters(COSBase filters) throws IOException {
setItem(COSName.FILTER, filters);
// kill cached filtered streams
filteredStream = null;
}
set the filters to be applied to the stream. |