private TikaInputStream runFilter(COSName filterCOSName, TikaInputStream tis,
                                      COSDictionary filterParameters, int filterIndex)
            throws IOException {

        Filter filter = filterFactory.getFilter(filterCOSName);
        if (tis.getLength() < 100000000) {
            try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
                filter.encode(tis, bos, filterParameters, filterIndex);
                bos.flush();
                bos.close();
                return TikaInputStream.get(bos.toByteArray());
            } finally {
                tis.close();
            }
        } else {
            TemporaryResources tmp = new TemporaryResources();
            Path p = tmp.createTempFile();
            try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(p))) {
                filter.encode(tis, os, filterParameters, filterIndex);
            } finally {
                tis.close();
            }
            return TikaInputStream.get(p, new Metadata(), tmp);
        }
    }
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