public class

Filter

extends Object
java.lang.Object
   ↳ com.pdftron.filters.Filter
Known Direct Subclasses
Known Indirect Subclasses

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
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

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

public boolean canSeek ()

determine whether the stream supports seeking

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

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

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.

public void flush ()

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

public void flushAll ()

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

public Filter getAttachedFilter ()

Get the attached filter.

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

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).

public String getFilePath ()

Get the file path.

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

public String getName ()

Get the name.

Returns
  • - descriptive name of the filter.

public Filter getSourceFilter ()

Get the source filter.

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

public boolean isInputFilter ()

Checks if is input filter.

Returns
  • - boolean indicating whether this is an input filter.

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.

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

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

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.

public long tell ()

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

Returns
  • - The current position in the stream

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.