* {@inheritDoc}
*/
protected int output(OutputStream stream) throws IOException {
setupFilterList();
CountingOutputStream cout = new CountingOutputStream(stream);
Writer writer = PDFDocument.getWriterFor(cout);
writer.write(getObjectID());
//int length = 0;
StreamCache encodedStream = null;
PDFNumber refLength = null;
final Object lengthEntry;
if (getDocument().isEncodingOnTheFly()) {
refLength = new PDFNumber();
getDocumentSafely().registerObject(refLength);
lengthEntry = refLength;
} else {
encodedStream = encodeStream();
lengthEntry = new Integer(encodedStream.getSize() + 1);
}
populateStreamDict(lengthEntry);
writeDictionary(cout, writer);
//Send encoded stream to target OutputStream
writer.flush();
if (encodedStream == null) {
encodeAndWriteStream(cout, refLength);
} else {
outputStreamData(encodedStream, cout);
encodedStream.clear(); //Encoded stream can now be discarded
}
writer.write("\nendobj\n");
writer.flush();
return cout.getCount();
}