Interface BytesDocumentFilter

    • Method Detail

      • canFilter

        PreFilterCheck canFilter​(NoContentDocument document,
                                 FilterContext context)
        Checks if the document can be filtered.

        This provides the filter an opportunity to avoid the filtering method from being called. This can provide some speed up by avoiding a conversion of the document to BytesDocument when the document will not be filtered.

        Typically this method is used to inspect non content parts of the document to determine if the document looks like something that can be filtered. For example we may check that the document has a mime type of application/pdf before we attempt to do any filtering of the document.

        The result of this method determines if the filter method is called, it is acceptable for this method to return true while the filter method could return FilterResult.skipped(). As it may not be known if the filter should be skipped until the document contents are inspected.

        document - which may have its meta data and other non content parts inspected to determine if an attempt should be made to filter the document.
        context - under which the filter is running.
        PreFilterCheck.ATTEMPT_FILTER if the filter method should be called otherwise PreFilterCheck.SKIP_FILTER, to skip this Filter.
      • filter

        default FilterResult filter​(FilterableDocument document,
                                    FilterContext context)
        Filter method responsible for calling canFilter(NoContentDocument, FilterContext) and filterAsBytesDocument(BytesDocument, FilterContext)

        Typically this method should not be overridden.

        Filter a document.

        Typically the interfaces BytesDocumentFilter or StringDocumentFilter are implemented instead of Filter as they gives easier access to the document content. This interface should be implemented when the filter does not need to read or modify the documents content.

        Filtering only throws unchecked exceptions. In the case a unchecked exception is thrown filtering for that document is stopped and the document may or not be stored. When an exception is raised in a filter the filter can choose to:

        • Re-throw the exception as a unchecked exception, ideally as a FilterException.
        • Return FilterResult.isSkipped() to indicate that the filter should be considered skipped, in the case of a choice filter this will cause it to try the next filter.
        • Ignore the exception and return any other type of FilterResult with or without changes to the given document.
        If a checked Exception is raised the filter should catch the exception and typically return the original document or return FilterResult.skipped().
        Specified by:
        filter in interface Filter
        document - The document to be filtered.
        context - The context the filter is running under.
        A FilterResult which comes from one of the static methods on FilterResult.