Interface BytesDocumentFilter
-
- All Superinterfaces:
Filter
,NamedFilter
public interface BytesDocumentFilter extends Filter
Filters a document where the content is converted to a byte[].The document will only call
filterAsBytesDocument(BytesDocument, FilterContext)
ifcanFilter(NoContentDocument, FilterContext)
returns true.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description PreFilterCheck
canFilter(NoContentDocument document, FilterContext context)
Checks if the document can be filtered.default FilterResult
filter(FilterableDocument document, FilterContext context)
Filter method responsible for callingcanFilter(NoContentDocument, FilterContext)
andfilterAsBytesDocument(BytesDocument, FilterContext)
FilterResult
filterAsBytesDocument(BytesDocument document, FilterContext context)
Filters theBytesDocument
-
Methods inherited from interface com.funnelback.filter.api.filters.NamedFilter
getFilterName
-
-
-
-
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 returnFilterResult.skipped()
. As it may not be known if the filter should be skipped until the document contents are inspected.- Parameters:
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.- Returns:
PreFilterCheck.ATTEMPT_FILTER
if the filter method should be called otherwisePreFilterCheck.SKIP_FILTER
, to skip this Filter.
-
filterAsBytesDocument
FilterResult filterAsBytesDocument(BytesDocument document, FilterContext context)
Filters theBytesDocument
Called when
canFilter(NoContentDocument, FilterContext)
returnsPreFilterCheck.ATTEMPT_FILTER
- Parameters:
document
- to be filtered, which has been converted into a RawFilterableDocumentcontext
- under which the filter is running.- Returns:
- the result of executing this filter, the result may be
FilterResult.skipped()
.
-
filter
default FilterResult filter(FilterableDocument document, FilterContext context)
Filter method responsible for callingcanFilter(NoContentDocument, FilterContext)
andfilterAsBytesDocument(BytesDocument, FilterContext)
Typically this method should not be overridden.
Filter a document.Typically the interfaces
BytesDocumentFilter
orStringDocumentFilter
are implemented instead ofFilter
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.
FilterResult.skipped()
.- Specified by:
filter
in interfaceFilter
- Parameters:
document
- The document to be filtered.context
- The context the filter is running under.- Returns:
- A
FilterResult
which comes from one of the static methods onFilterResult
.
- Re-throw the exception as a unchecked exception, ideally as a
-
-