public class InputStreamDigester extends java.lang.Object implements DigestingParser.Digester
| Modifier and Type | Class and Description |
|---|---|
private static class |
InputStreamDigester.SimpleBoundedInputStream
Very slight modification of Commons' BoundedInputStream
so that we can figure out if this hit the bound or not.
|
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
algorithm |
private java.lang.String |
algorithmKeyName |
private DigestingParser.Encoder |
encoder |
private int |
markLimit |
| Constructor and Description |
|---|
InputStreamDigester(int markLimit,
java.lang.String algorithm,
DigestingParser.Encoder encoder) |
InputStreamDigester(int markLimit,
java.lang.String algorithm,
java.lang.String algorithmKeyName,
DigestingParser.Encoder encoder) |
| Modifier and Type | Method and Description |
|---|---|
void |
digest(java.io.InputStream is,
Metadata metadata,
ParseContext parseContext)
Digests an InputStream and sets the appropriate value(s) in the metadata.
|
private void |
digestFile(java.io.File f,
Metadata m) |
private boolean |
digestStream(java.io.InputStream is,
Metadata metadata) |
private java.lang.String |
getMetadataKey() |
protected java.security.Provider |
getProvider()
When subclassing this, becare to ensure that your provider is
thread-safe (not likely) or return a new provider with each call.
|
private java.security.MessageDigest |
newMessageDigest() |
private static java.security.MessageDigest |
updateDigest(java.security.MessageDigest digest,
java.io.InputStream data)
Copied from commons-codec
|
private final java.lang.String algorithm
private final java.lang.String algorithmKeyName
private final DigestingParser.Encoder encoder
private final int markLimit
public InputStreamDigester(int markLimit,
java.lang.String algorithm,
DigestingParser.Encoder encoder)
public InputStreamDigester(int markLimit,
java.lang.String algorithm,
java.lang.String algorithmKeyName,
DigestingParser.Encoder encoder)
markLimit - limit in bytes to allow for mark/reset. If the inputstream is longer
than this limit, the stream will be reset and then spooled to a temporary file.
Throws IllegalArgumentException if < 0.algorithm - name of the digest algorithm to retrieve from the ProvideralgorithmKeyName - name of the algorithm to store
as part of the key in the metadata
when digest(InputStream, Metadata, ParseContext) is calledencoder - encoder to convert the byte array returned from the digester to a stringprivate java.security.MessageDigest newMessageDigest()
protected java.security.Provider getProvider()
public void digest(java.io.InputStream is,
Metadata metadata,
ParseContext parseContext)
throws java.io.IOException
DigestingParser.Digester
The given stream is guaranteed to support the
mark feature and the detector
is expected to mark the stream before
reading any bytes from it, and to reset
the stream before returning. The stream must not be closed by the
detector.
digest in interface DigestingParser.Digesteris - InputStream to digest. Best to use a TikaInputStream because
of potential need to spool to disk. InputStream must
support mark/reset.metadata - metadata in which to store the digest informationparseContext - ParseContext -- not actually used yet, but there for future expansionjava.io.IOException - on IO problem or IllegalArgumentException if algorithm couldn't be foundprivate java.lang.String getMetadataKey()
private void digestFile(java.io.File f,
Metadata m)
throws java.io.IOException
java.io.IOExceptionprivate boolean digestStream(java.io.InputStream is,
Metadata metadata)
throws java.io.IOException
is - input stream to read frommetadata - metadata for reporting the digestjava.io.IOExceptionprivate static java.security.MessageDigest updateDigest(java.security.MessageDigest digest,
java.io.InputStream data)
throws java.io.IOException
java.io.IOException