File Content Extraction 26.3
Filter SDK Java Programming Guide

# Filter in File or Stream Mode

To filter files using the methods in the `Filter` class

1. Instantiate a `Filter` object:

   - Use the constructor `Filter(String license)`. For example:

         m_objFilter = new Filter("YOUR_KEYVIEW_LICENSE");

   - Use the constructor `Filter(String license, java.lang.String outputCharSet, long filterFlags)`. For example:

         m_objFilter = new Filter("YOUR_KEYVIEW_LICENSE", Filter.CHARSET_UTF8, Filter.FILTERFLAG_OOPLOGON);

   The Filter flags provide instructions on how to process a file or stream. For example, they specify whether an error log is generated during filtering (`FILTERFLAG_OOPLOGON`) or whether headers and footers are extracted from the document (`FILTERFLAG_HEADERFOOTERTAGS`).

2. Set the location of the Filter libraries by calling the `setFilterDirectory(java.lang.String directory)` method. These libraries are normally stored in the directory `install\OS\bin`, where `install` is the path name of the Filter installation directory and `OS` is the name of the operating system. For example:

       m_objFilter.setFilterDirectory(m_filterDirectory);

3. Set the input source as either a file or input stream by calling the `setInputSource` method.

          m_objFilter.setInputSource(m_extractDir + filename);

4. Filter the file or stream by calling either the `filterTo` or `doFilterChunk` method. The `filterTo` method extracts the data to a file or a stream. The `doFilterChunk` method extracts one chunk of data from a file or a stream. It must be called repeatedly until the entire buffer is filtered.

   If filtering in file mode, use the following code:

          {
              m_objFilter.filterTo(m_extractDir + filename + m_extension);
          }

   If filtering in stream mode, use the following code:

          {
              outf = new File(m_extractDir + filename + m_extension);
       	fos = new FileOutputStream(outf);
       	m_objFilter.filterTo(fos);
       	fos.close();
          }
       }

5. Terminate the filtering session and free allocated system resources by calling the `shutdownFilter()` method.

         m_objFilter.shutdownFilter();

Copyright 1997-2026 Open Text
Version 26.3 | Last updated July 2026

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to MFI-swpdl.idoldocsfeedback@opentext.com.

We appreciate your feedback!

Product: File Content Extraction 26.3

Topic Title: Filter in File or Stream Mode