org.apache.pdfbox.filter

## Class Filter

- java.lang.Object
- - org.apache.pdfbox.filter.Filter

Direct Known Subclasses:
  JPXFilter, LZWFilter

    public abstract class Filter
    extends Object

A filter for stream data.

Author:
  Ben Litchfield, John Hewson

### Field Summary

Fields
`static String` `SYSPROP_DEFLATELEVEL` Compression Level System Property.

### Constructor Summary

Constructors
`protected` `Filter()` Constructor.

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
`abstract DecodeResult` `decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index)` Decodes data, producing the original non-encoded data.
`DecodeResult` `decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index, DecodeOptions options)` Decodes data, with optional DecodeOptions.
`protected abstract void` `encode(InputStream input, OutputStream encoded, COSDictionary parameters)`
`void` `encode(InputStream input, OutputStream encoded, COSDictionary parameters, int index)` Encodes data.
`protected static ImageReader` `findImageReader(String formatName, String errorCause)` Finds a suitable image reader for a format.
`static ImageReader` `findRasterReader(String formatName, String errorCause)` Finds a suitable image reader for an image format.
`static int` `getCompressionLevel()`
`protected COSDictionary` `getDecodeParams(COSDictionary dictionary, int index)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### SYSPROP_DEFLATELEVEL

    public static final String SYSPROP_DEFLATELEVEL

Compression Level System Property. Set this to a value from 0 to 9 to change the zlib deflate compression level used to compress /Flate streams. The default value is -1 which is `Deflater.DEFAULT_COMPRESSION`. To set maximum compression, use `System.setProperty(Filter.SYSPROP_DEFLATELEVEL, "9");`

See Also:
  Constant Field Values

### Constructor Detail

#### Filter

    protected Filter()

Constructor.

### Method Detail

#### decode

    public abstract DecodeResult decode(InputStream encoded,
                                        OutputStream decoded,
                                        COSDictionary parameters,
                                        int index)
                                 throws IOException

Decodes data, producing the original non-encoded data.

Parameters:
  `encoded` - the encoded byte stream
  `decoded` - the stream where decoded data will be written
  `parameters` - the parameters used for decoding
  `index` - the index to the filter being decoded
Returns:
  repaired parameters dictionary, or the original parameters dictionary
Throws:
  `IOException` - if the stream cannot be decoded

#### decode

    public DecodeResult decode(InputStream encoded,
                               OutputStream decoded,
                               COSDictionary parameters,
                               int index,
                               DecodeOptions options)
                        throws IOException

Decodes data, with optional DecodeOptions. Not all filters support all options, and so callers should check the options' `honored` flag to test if they were applied.

Parameters:
  `encoded` - the encoded byte stream
  `decoded` - the stream where decoded data will be written
  `parameters` - the parameters used for decoding
  `index` - the index to the filter being decoded
  `options` - additional options for decoding
Returns:
  repaired parameters dictionary, or the original parameters dictionary
Throws:
  `IOException` - if the stream cannot be decoded

#### encode

    public final void encode(InputStream input,
                             OutputStream encoded,
                             COSDictionary parameters,
                             int index)
                      throws IOException

Encodes data.

Parameters:
  `input` - the byte stream to encode
  `encoded` - the stream where encoded data will be written
  `parameters` - the parameters used for encoding
  `index` - the index to the filter being encoded
Throws:
  `IOException` - if the stream cannot be encoded

#### encode

    protected abstract void encode(InputStream input,
                                   OutputStream encoded,
                                   COSDictionary parameters)
                            throws IOException

Throws:
  `IOException`

#### getDecodeParams

    protected COSDictionary getDecodeParams(COSDictionary dictionary,
                                            int index)

#### findImageReader

    protected static ImageReader findImageReader(String formatName,
                                                 String errorCause)
                                          throws MissingImageReaderException

Finds a suitable image reader for a format.

Parameters:
  `formatName` - The format to search for.
  `errorCause` - The probably cause if something goes wrong.
Returns:
  The image reader for the format.
Throws:
  `MissingImageReaderException` - if no image reader is found.

#### findRasterReader

    public static ImageReader findRasterReader(String formatName,
                                               String errorCause)
                                        throws MissingImageReaderException

Finds a suitable image reader for an image format.

Parameters:
  `formatName` - The image format to search for.
  `errorCause` - The probably cause if something goes wrong.
Returns:
  The image reader for the format.
Throws:
  `MissingImageReaderException` - if no image reader is found.

#### getCompressionLevel

    public static int getCompressionLevel()

Returns:
  the ZIP compression level configured for PDFBox