Class DigestSink

java.lang.Object
java.io.OutputStream
org.apache.tika.digest.DigestSink
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public abstract class DigestSink extends OutputStream
A sink returned by Digester.digestSink(org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext): bytes written to it are digested, and the value(s) reach the metadata only if the producer calls commit().

Commit is explicit because the alternative -- publish on close unless something remembered to cancel -- makes every unanticipated exit (a checked exception, an Error, a producer that closes the sink itself) publish a digest of whatever bytes happened to arrive. A digest of a partial write is worse than no digest: it is wrong, and it is stably wrong, so every failure of the same shape produces the same plausible value.

Contract:

  • Write the content, then commit(), then close() -- close in a finally or via try-with-resources.
  • close() releases resources either way, and publishes only if commit() was called first. It is idempotent.
  • commit() after close() throws IllegalStateException: the chance to publish is gone, and failing loudly beats a silently missing digest.
  • Writing after close() throws IOException.
  • All methods must be called from the producing thread.
  • Constructor Details

    • DigestSink

      public DigestSink()
  • Method Details