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(InputStream inputStream)
Creates a new instance, which calculates a signature on the given stream, using a
MessageDigest with the
"MD5" algorithm. |
MessageDigestCalculatingInputStream(InputStream inputStream,
MessageDigest MessageDigest)
Creates a new instance, which calculates a signature on the given stream,
using the given
MessageDigest . |
MessageDigestCalculatingInputStream(InputStream inputStream,
String algorithm)
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 |
---|---|
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(InputStream inputStream, MessageDigest MessageDigest)
MessageDigest
.inputStream
- the stream to calculate the message digest forMessageDigest
- the message digest to usepublic MessageDigestCalculatingInputStream(InputStream inputStream, String algorithm) throws NoSuchAlgorithmException
MessageDigest
with the
given algorithm.inputStream
- the stream to calculate the message digest foralgorithm
- the name of the algorithm to useNoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified
algorithm.public MessageDigestCalculatingInputStream(InputStream inputStream) throws NoSuchAlgorithmException
MessageDigest
with the
"MD5" algorithm.inputStream
- the stream to calculate the message digest forNoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified
algorithm.public 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()
.Jas4pp 1.5 © Java Analysis Studio for Particle Physics