Filter in File or Stream Mode

To filter a file or stream

  1. Instantiate a LicenseInfo object to store your KeyView license.

    LicenseInfo myLicense = new LicenseInfo("my_organization", "my_key");
  2. Instantiate a Filter object, providing your LicenseInfo object.

    • To instantiate the Filter object with the default output character set and filtering options:

      objFilter = new Filter(myLicense);
    • To instantiate the Filter object with your chosen output character set and filtering options:

      objFilter = new Filter(Charset.KVCS_UTF8,
          FilterConstant.FilterFlagConstant.FILTERFLAG_OOPLOGON,
          myLicense);

      The filter flags provide instructions about how to process a file or stream. For example, you can specify whether to run filtering out-of-process (FILTERFLAG_OUTOFPROCESS), whether to log errors during filtering (FILTERFLAG_OOPLOGON), and whether to extract headers and footers from a document (FILTERFLAG_HEADERFOOTERTAGS).

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

  3. Set the location of the Filter libraries by setting the FilterDirectory property. These libraries are provided in the directory PLATFORM\bin, in the KeyView Filter SDK, where PLATFORM is the name of the platform. For example:

    objFilter.FilterDirectory = "C:\\KeyviewFilterSDK\\WINDOWS_X86_64\\bin";
  4. Set the input source as either a file or input stream by calling the SetInputSource method.

    objFilter.SetInputSource(m_inFile);
  5. 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();
        }
  6. Terminate the filtering session and free allocated system resources by calling the ShutdownFilter() method. This must be called within a Finally block.

    m_objFilter.ShutdownFilter();