To filter a file or stream
Instantiate a LicenseInfo
object to store your KeyView license.
LicenseInfo myLicense = new LicenseInfo("my_organization", "my_key");
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.
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";
Set the input source as either a file or input stream by calling the SetInputSource
method.
objFilter.SetInputSource(m_inFile);
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(); }
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();