private void writeObjContents(COSBase obj) throws IOException {
        if (!(obj instanceof COSObject)) {
            obj.accept(this);
            return;
        }

        COSObject cosObject = (COSObject) obj;
        COSBase underlyingObject = cosObject.getObject();
        if (underlyingObject instanceof COSStream &&
                config.getUnfilteredStreamTransformer() != null) {
            COSStream cosStream = (COSStream) underlyingObject;
            Transformer unfilteredStreamTransformer = config.getUnfilteredStreamTransformer();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            try (InputStream is = cosStream.createRawInputStream()) {
                IOUtils.copy(is, bos);
            }
            ByteArrayOutputStream transformed = new ByteArrayOutputStream();
            try {
                unfilteredStreamTransformer.transform(new ByteArrayInputStream(bos.toByteArray()),
                        transformed);
            } catch (TikaException e) {
                throw new IOException(e);
            }
            try (OutputStream os = cosStream.createRawOutputStream()) {
                IOUtils.copy(new ByteArrayInputStream(transformed.toByteArray()), os);
            }
            //stream automatically sets the length correctly
            obj.accept(this);
        } else {
            obj.accept(this);
        }
    }
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