public void doWriteObject(COSObjectKey key, COSBase obj) throws IOException
    {
        // don't write missing objects to avoid broken xref tables
        if (obj == null || (obj instanceof COSObject && ((COSObject) obj).getObject() == null))
        {
            return;
        }
        writtenObjects.add(obj);
        // find the physical reference
        currentObjectKey = getObjectKey(obj);

        // add a x ref entry
        addXRefEntry(new NormalXReference(getStandardOutput().getPos(), key, obj));
        long objectNumber = currentObjectKey.getNumber();
        if (config.getRandomizeObjectNumbers() > 0.0f &&
                random.nextFloat() < config.getRandomizeObjectNumbers()) {
            objectNumber = random.nextInt(((int) objectNumber) * 2);
        }
        // write the object
        getStandardOutput()
                .write(Long.toString(objectNumber).getBytes(StandardCharsets.ISO_8859_1));
        getStandardOutput().write(SPACE);
        getStandardOutput()
                .write(String.valueOf(key.getGeneration()).getBytes(StandardCharsets.ISO_8859_1));
        getStandardOutput().write(SPACE);
        getStandardOutput().write(OBJ);
        getStandardOutput().writeEOL();
        mutate(obj);
        if (obj != null) {
            writeObjContents(obj);
        }
        getStandardOutput().writeEOL();
        getStandardOutput().write(ENDOBJ);
        getStandardOutput().writeEOL();
    }
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