private void addObjectToWrite(COSBase object) {
        COSBase actual = object;
        if (actual instanceof COSObject) {
            actual = ((COSObject) actual).getObject();
        }

        if (!writtenObjects.contains(object) && !objectsToWriteSet.contains(object) &&
                !actualsAdded.contains(actual)) {
            COSBase cosBase = null;
            COSObjectKey cosObjectKey = null;
            if (actual != null) {
                cosObjectKey = objectKeys.get(actual);
            }
            if (cosObjectKey != null) {
                cosBase = keyObject.get(cosObjectKey);
            }
            if (actual != null && objectKeys.containsKey(actual) &&
                    object instanceof COSUpdateInfo &&
                    !((COSUpdateInfo) object).isNeedToBeUpdated() &&
                    cosBase instanceof COSUpdateInfo &&
                    !((COSUpdateInfo) cosBase).isNeedToBeUpdated()) {
                return;
            }
            objectsToWrite.add(object);
            objectsToWriteSet.add(object);
            if (actual != null) {
                actualsAdded.add(actual);
            }
        }
    }
This will write the body of the document.

@param doc The document to write the body for.
@throws IOException If there is an error writing the data.
tika-fuzzing/src/main/java/org/apache/tika/fuzzing/pdf/EvilCOSWriter.java