# Filter in File or Stream Mode

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

1. Instantiate a `Filter` object using either the default constructor or the constructor that sets the output character set and filter flags:

   1. Use the default constructor `Filter()`. For example:

          m_objFilter = new Filter();

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

          m_objFilter = new Filter(outputCharSet, 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`).

   NOTE: Filter runs out of process by default. See The Filter Process Model for more information.

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 2016-2020 Micro Focus or one of its affiliates | Send documentation feedback Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a mail client, and then send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm