public class MessageDigestCalculatingInputStream extends ObservableInputStream
ObservableInputStream
. It
creates its own ObservableInputStream.Observer
,
which calculates a checksum using a MessageDigest, for example an MD5 sum.
Note: Neither ObservableInputStream
, nor MessageDigest
,
are thread safe. So is MessageDigestCalculatingInputStream
.Modifier and Type | Class and Description |
---|---|
static class |
MessageDigestCalculatingInputStream.MessageDigestMaintainingObserver
Maintains the message digest.
|
ObservableInputStream.Observer
Constructor and Description |
---|
MessageDigestCalculatingInputStream(java.io.InputStream pStream)
Creates a new instance, which calculates a signature on the given stream,
using a
MessageDigest with the "MD5" algorithm. |
MessageDigestCalculatingInputStream(java.io.InputStream pStream,
java.security.MessageDigest pDigest)
Creates a new instance, which calculates a signature on the given stream,
using the given
MessageDigest . |
MessageDigestCalculatingInputStream(java.io.InputStream pStream,
java.lang.String pAlgorithm)
Creates a new instance, which calculates a signature on the given stream,
using a
MessageDigest with the given algorithm. |
Modifier and Type | Method and Description |
---|---|
java.security.MessageDigest |
getMessageDigest()
Returns the
MessageDigest , which is being used for generating the
checksum. |
add, close, consume, read, read, read, remove, removeAllObservers
available, mark, markSupported, reset, skip
public MessageDigestCalculatingInputStream(java.io.InputStream pStream, java.security.MessageDigest pDigest)
MessageDigest
.pStream
- the stream to calculate the message digest forpDigest
- the message digest to usepublic MessageDigestCalculatingInputStream(java.io.InputStream pStream, java.lang.String pAlgorithm) throws java.security.NoSuchAlgorithmException
MessageDigest
with the given algorithm.pStream
- the stream to calculate the message digest forpAlgorithm
- the name of the algorithm to usejava.security.NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.public MessageDigestCalculatingInputStream(java.io.InputStream pStream) throws java.security.NoSuchAlgorithmException
MessageDigest
with the "MD5" algorithm.pStream
- the stream to calculate the message digest forjava.security.NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.public java.security.MessageDigest getMessageDigest()
MessageDigest
, which is being used for generating the
checksum.
Note: The checksum will only reflect the data, which has been read so far.
This is probably not, what you expect. Make sure, that the complete data has been
read, if that is what you want. The easiest way to do so is by invoking
ObservableInputStream.consume()
.Copyright © 2010 - 2020 Adobe. All Rights Reserved