private byte[] getBytes(OutputStream stream) throws IOException {
        if (stream instanceof ByteArrayOutputStream) {
            return ((ByteArrayOutputStream) stream).toByteArray();
        } else if (stream instanceof UnsynchronizedByteArrayOutputStream) {
            return ((UnsynchronizedByteArrayOutputStream) stream).toByteArray();
        }
        throw new IOException("OutputStream " + stream.getClass().getName() + " is not supported");
    }
This will write the fdf document.

@param doc The document to write.
@throws IOException If an error occurs while generating the data.
tika-fuzzing/src/main/java/org/apache/tika/fuzzing/pdf/EvilCOSWriter.java