Class EncodingProbeCache

java.lang.Object
org.apache.tika.detect.EncodingProbeCache

public class EncodingProbeCache extends Object
Caches the raw encoding-detection probe (the leading bytes read for detection) so that multiple detectors in a chain do not each re-read and re-tag-strip the same bytes. For example a statistical detector and a downstream meta detector that re-reads the bytes for arbitration can share one probe.

An instance is held by EncodingDetectorContext, so it inherits that context's per-detection lifecycle: created fresh per detection and discarded with the context immediately afterwards. That matters because a ParseContext flows on into recursive (attachment/embedded) parsing — a probe must never outlive the single detection it was read for.

Not thread-safe: a single detection runs its detectors sequentially on one thread. The cache is keyed by the probe parameters — get(int, int) returns the cached probe only when both contentTarget and rawCap match what it was stored with, so a detector that wants a differently-sized probe transparently reads (and caches) its own.

The cached array is shared read-only state; callers must not mutate it in place.

  • Constructor Details

    • EncodingProbeCache

      public EncodingProbeCache()
  • Method Details

    • get

      public byte[] get(int contentTarget, int rawCap)
      Returns:
      the cached probe if one was stored with the same contentTarget and rawCap; otherwise null
    • put

      public void put(byte[] probe, int contentTarget, int rawCap)
      Stores the probe bytes read with the given parameters.