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 | Description |
|---|---|---|
static class |
MessageDigestCalculatingInputStream.MessageDigestMaintainingObserver |
Maintains the message digest.
|
ObservableInputStream.Observer| Constructor | 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.lang.String pAlgorithm) |
Creates a new instance, which calculates a signature on the given stream,
using a
MessageDigest with the given 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. |
| Modifier and Type | Method | Description |
|---|---|---|
java.security.MessageDigest |
getMessageDigest() |
Returns the
MessageDigest, which is being used for generating the
checksum. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitadd, close, consume, getObservers, noteClosed, noteDataByte, noteDataBytes, noteError, noteFinished, read, read, read, remove, removeAllObserversafterRead, available, beforeRead, handleIOException, mark, markSupported, reset, skippublic 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().