Class MetadataFilter

java.lang.Object
org.apache.tika.metadata.filter.MetadataFilter
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable
Direct Known Subclasses:
AbstractEmbeddingFilter, CompositeMetadataFilter, MetadataFilterBase, NoOpFilter, RemoveByMimeMetadataFilter

public abstract class MetadataFilter extends Object implements Serializable, Closeable
See Also:
  • Constructor Details

    • MetadataFilter

      public MetadataFilter()
  • Method Details

    • filter

      public final void filter(List<Metadata> metadataList, ParseContext parseContext) throws TikaException
      Filters the metadata list in place using per-request context. The list and the metadata objects within it may be modified. Callers must pass a mutable list and should make a defensive copy before calling if the original data must be preserved.
      Parameters:
      metadataList - the list to filter (must be mutable)
      parseContext - per-request context (e.g. skip flags, runtime config)
      Throws:
      TikaException - if filtering fails
    • doFilter

      protected abstract void doFilter(List<Metadata> metadataList, ParseContext parseContext) throws TikaException
      Applies the filter in place. A filter that needs to write a reserved Tika-native (tk:) key by name (rather than via its Property) should call Metadata.addTrusted(java.lang.String, java.lang.String) / Metadata.setTrusted(java.lang.String, java.lang.String) explicitly at that write.
      Parameters:
      metadataList - the list to filter (must be mutable)
      parseContext - per-request context
      Throws:
      TikaException - if filtering fails
    • filter

      public void filter(List<Metadata> metadataList) throws TikaException
      Convenience overload for callers that have no per-request context. Delegates to filter(List, ParseContext) with an empty context.
      Throws:
      TikaException
    • close

      public void close() throws IOException
      Releases any resources held by this filter (e.g. HTTP connection pools, thread pools). The default implementation is a no-op; filters that hold long-lived resources should override this.

      Callers that control the filter lifecycle (e.g. PipesServer, try-with-resources blocks) should call this when the filter is no longer needed.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException