class FlateFilter extends Filter
{
    private static final Logger LOG = LogManager.getLogger(FlateFilter.class);

    @Override
    public DecodeResult decode(InputStream encoded, OutputStream decoded,
                                         COSDictionary parameters, int index) throws IOException
    {
        final COSDictionary decodeParams = getDecodeParams(parameters, index);

        try
        {
            decompress(encoded, Predictor.wrapPredictor(decoded, decodeParams));
        }
        catch (DataFormatException e)
        {
            // if the stream is corrupt a DataFormatException may occur
            LOG.error("FlateFilter: stop reading corrupt stream due to a DataFormatException");

            // re-throw the exception
            throw new IOException(e);
        }
        return new DecodeResult(parameters);
    }

    // Use Inflater instead of InflateInputStream to avoid an EOFException due to a probably
    // missing Z_STREAM_END, see PDFBOX-1232 for details
    private void decompress(InputStream in, OutputStream out) throws IOException, DataFormatException 
    {<FILL_FUNCTION_BODY>}
    
    @Override
    protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
            throws IOException
    {
        int compressionLevel = getCompressionLevel();
        Deflater deflater = new Deflater(compressionLevel);
        try (DeflaterOutputStream out = new DeflaterOutputStream(encoded,deflater))
        {
            input.transferTo(out);
        }
        encoded.flush();
        deflater.end();
    }
}
 
        byte[] buf = new byte[2048];
        // skip zlib header
        in.read();
        in.read();
        int read = in.read(buf); 
        if (read > 0) 
        { 
            // use nowrap mode to bypass zlib-header and checksum to avoid a DataFormatException
            Inflater inflater = new Inflater(true); 
            inflater.setInput(buf,0,read);
            byte[] res = new byte[1024];
            boolean dataWritten = false;
            try
            {
                while (true) 
                { 
                    int resRead = 0;
                    try
                    {
                        resRead = inflater.inflate(res);
                    }
                    catch(DataFormatException exception)
                    {
                        if (dataWritten)
                        {
                            // some data could be read -> don't throw an exception
                            LOG.warn("FlateFilter: premature end of stream due to a DataFormatException");
                            break;
                        }
                        else
                        {
                            // nothing could be read -> re-throw exception
                            throw exception;
                        }
                    }
                    if (resRead != 0) 
                    { 
                        out.write(res,0,resRead);
                        dataWritten = true;
                        continue; 
                    } 
                    if (inflater.finished() || inflater.needsDictionary() || in.available() == 0) 
                    {
                        break;
                    } 
                    read = in.read(buf); 
                    inflater.setInput(buf,0,read);
                }
            }
            finally
            {
                inflater.end();
            }
        }
        out.flush();
    
<methods>public abstract org.apache.pdfbox.filter.DecodeResult decode(java.io.InputStream, java.io.OutputStream, org.apache.pdfbox.cos.COSDictionary, int) throws java.io.IOException,public org.apache.pdfbox.filter.DecodeResult decode(java.io.InputStream, java.io.OutputStream, org.apache.pdfbox.cos.COSDictionary, int, org.apache.pdfbox.filter.DecodeOptions) throws java.io.IOException,public static org.apache.pdfbox.io.RandomAccessRead decode(java.io.InputStream, List<org.apache.pdfbox.filter.Filter>, org.apache.pdfbox.cos.COSDictionary, org.apache.pdfbox.filter.DecodeOptions, List<org.apache.pdfbox.filter.DecodeResult>) throws java.io.IOException,public final void encode(java.io.InputStream, java.io.OutputStream, org.apache.pdfbox.cos.COSDictionary, int) throws java.io.IOException,public static final javax.imageio.ImageReader findImageReader(java.lang.String, java.lang.String) throws org.apache.pdfbox.filter.MissingImageReaderException,public static int getCompressionLevel() <variables>private static final Logger LOG,public static final java.lang.String SYSPROP_DEFLATELEVEL