Package org.apache.tika.digest
Class DigestSink
java.lang.Object
java.io.OutputStream
org.apache.tika.digest.DigestSink
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
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(), thenclose()-- close in afinallyor via try-with-resources. close()releases resources either way, and publishes only ifcommit()was called first. It is idempotent.commit()afterclose()throwsIllegalStateException: the chance to publish is gone, and failing loudly beats a silently missing digest.- Writing after
close()throwsIOException. - All methods must be called from the producing thread.
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write, write, write
-
Constructor Details
-
DigestSink
public DigestSink()
-
-
Method Details
-
commit
public final void commit()Marks the content complete, soclose()publishes it. Idempotent.- Throws:
IllegalStateException- if this sink is already closed
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
finish
Called once, from the firstclose(). Release resources either way; set the metadata only whenpublishis true.- Throws:
IOException
-
ensureOpen
For subclasses' write methods.- Throws:
IOException
-