Summary: Methods | Inherited Methods | [Expand All]
public class

# Filter

extends Object
implements AutoCloseable

java.lang.Object
↳ | com.pdftron.filters.Filter

Known Direct Subclasses ASCII85Encode, CustomFilter, FlateEncode, Image2RGB, Image2RGBA, MappedFile, MemoryFilter
ASCII85Encode | ASCII85Encode filter can be used to encode any data stream into a stream that does not contain any binary characters.
CustomFilter | CustomFilter allows for customizing the reading and writing process.
FlateEncode | FlateEncode filter can be used to compress any data stream using Flate (i.e.
Image2RGB | Image2RGB is a filter that can decompress and normalize any PDF image stream (e.g.
Image2RGBA | Image2RGBA is a filter that can decompress and normalize any PDF image stream (e.g.
MappedFile | MappedFile is a utility class to read files on a file system.
MemoryFilter | MemoryFilter is a memory buffer that can be used as a source or a sink Filter in the Filter pipeline.

Known Indirect Subclasses FileDescriptorFilter, FileDescriptorReadOnlyFilter, SecondaryFileFilter
FileDescriptorFilter |
FileDescriptorReadOnlyFilter |
SecondaryFileFilter | This class is used for creating a `PDFDoc` from Android content Uri.

## Class Overview

Provides a generic view of a sequence of bytes. A Filter is the abstract base class of all filters. A filter is an abstraction of a sequence of bytes, such as a file, an input/output device, an inter-process communication pipe, or a TCP/IP socket. The Filter class and its derived classes provide a generic view of these different types of input and output, isolating the programmer from the specific details of the operating system and the underlying devices. Besides providing access to input/output sources Filters can be also to transform the data (e.g. to compress the data stream, to normalize the image data, to encrypt data, etc). Filters can also be attached to each other to form pipelines. For example, a filter used to open an image data file can be attached to a filter that decompresses the data, which is attached to another filter that will normalize the image data. Depending on the underlying data source or repository, filters might support only some of these capabilities. An application can query a stream for its capabilities by using the IsInputFilter() and CanSeek() properties.

Note: To read or write data to a filter, a user will tipically use FilterReader/FilterWriter class instead of using Filter methods. For example:

     MappedFile file = new MappedFile("my_stream.txt");
       FilterReader reader = new FilterReader(file);
       while (reader.read(...)) ...

## Summary

Public Methods
static Filter | __Create(long impl, Filter attached)
long | __GetHandle()
void | __SetRefHandle(Object ref)
void | attachFilter(Filter attach_filter) Attaches a filter to the this filter.
boolean | canSeek() determine whether the stream supports seeking
void | close() Frees the native memory of the object.
Filter | createInputIterator() Create Filter iterator.
void | destroy() Frees the native memory of the object.
void | flush() Forces any data remaining in the buffer to be written to input or output filter.
void | flushAll() Forces any data remaining in the filter chain to the source or destination.
Filter | getAttachedFilter() Get the attached filter.
String | getDecodeName() Get the decode name.
String | getFilePath() Get the file path.
String | getName() Get the name.
Filter | getSourceFilter() Get the source filter.
boolean | isInputFilter() Checks if is input filter.
Filter | releaseAttachedFilter() Release the ownership of the attached filter.
void | seek(long offset, int origin) When overridden in a derived class, sets the position within the current stream.
void | setStreamLength(long bytes) The functions specifies the length of the data stream.
long | size() Returns the size of buffer returned by Begin().
long | tell() Reports the current read position in the stream relative to the stream origin.
void | writeToFile(String path, boolean append) Writes the entire filter, starting at current position, to specified filepath.

[Expand] Inherited Methods
From class java.lang.Object
boolean | equals(Object arg0)
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()
From interface java.lang.AutoCloseable
abstract void | close()

## Public Methods

#### public static Filter __Create (long impl, Filter attached)

#### public long __GetHandle ()

#### public void __SetRefHandle (Object ref)

#### public void attachFilter (Filter attach_filter)

Attaches a filter to the this filter. If this filter owns another filter it will be deleted. This filter then becomes the owner of the attached filter.

##### Parameters

attach_filter | the attach_filter

##### Throws

PDFNetException |

#### public boolean canSeek ()

determine whether the stream supports seeking

##### Returns

- - true if the stream supports seeking; otherwise, false. default is to return false.

##### Throws

PDFNetException |

#### public void close ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

##### Throws

PDFNetException |

#### public Filter createInputIterator ()

Create Filter iterator. Filter iterator similar to a regular filter. However, there can be only one owner of the attached filter.

Note: - Derived classes should make sure that there is only one owner of the attached stream. Otherwise the attached stream may be deleted several times.

##### Returns

- the filter

##### Throws

PDFNetException |

#### public void destroy ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

##### Throws

PDFNetException |

#### public void flush ()

Forces any data remaining in the buffer to be written to input or output filter.

##### Throws

PDFNetException |

#### public void flushAll ()

Forces any data remaining in the filter chain to the source or destination.

##### Throws

PDFNetException |

#### public Filter getAttachedFilter ()

Get the attached filter.

##### Returns

- - returns attached Filter or a NULL filter if no filter is attached.

##### Throws

PDFNetException |

#### public String getDecodeName ()

Get the decode name.

##### Returns

- - string representing the name of corresponding decode filter as it should appear in document (e.g. both ASCIIHexDecode and ASCIIHexEncode should return ASCIIHexDecode).

##### Throws

PDFNetException |

#### public String getFilePath ()

Get the file path.

##### Returns

- the file path to the underlying file stream. Default implementation returns empty string.

##### Throws

PDFNetException |

#### public String getName ()

Get the name.

##### Returns

- - descriptive name of the filter.

##### Throws

PDFNetException |

#### public Filter getSourceFilter ()

Get the source filter.

##### Returns

- - returns the first filter in the chain (usually a file filter)

##### Throws

PDFNetException |

#### public boolean isInputFilter ()

Checks if is input filter.

##### Returns

- - boolean indicating whether this is an input filter.

##### Throws

PDFNetException |

#### public Filter releaseAttachedFilter ()

Release the ownership of the attached filter. After the attached filter is released this filter points to NULL filter.

##### Returns

- - Previously attached filter.

##### Throws

PDFNetException |

#### public void seek (long offset, int origin)

When overridden in a derived class, sets the position within the current stream.

Note: - After each Seek() operation the number of consumed bytes (i.e. Count()) is set to 0.

##### Parameters

offset | - A byte offset relative to origin. If offset is negative, the new position will precede the position specified by origin by the number of bytes specified by offset. If offset is zero, the new position will be the position specified by origin. If offset is positive, the new position will follow the position specified by origin by the number of bytes specified by offset.
origin | - A value of type ReferencePos indicating the reference point used to obtain the new position

##### Throws

PDFNetException |

#### public void setStreamLength (long bytes)

The functions specifies the length of the data stream. The default implementation does not do anything. For some derived filters such as file segment filter it may be useful to override this function in order to limit the stream.

##### Parameters

bytes | the new stream length

##### Throws

PDFNetException |

#### public long size ()

Returns the size of buffer returned by Begin(). If the Size() returns 0 end of data has been reached.

##### Returns

- - the size of buffer returned by Begin(). If the Size() returns 0 end of data has been reached.

##### Throws

PDFNetException |

#### public long tell ()

Reports the current read position in the stream relative to the stream origin.

##### Returns

- - The current position in the stream

##### Throws

PDFNetException |

#### public void writeToFile (String path, boolean append)

Writes the entire filter, starting at current position, to specified filepath. Should only be called on an input filter.

##### Parameters

path | the output filepath.
append | 'true' to append to existing file contents, 'false' to overwrite.