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
in
Constructor and Description |
---|
MessageDigestCalculatingInputStream(InputStream pStream)
Creates a new instance, which calculates a signature on the given stream,
using a
MessageDigest with the "MD5" algorithm. |
MessageDigestCalculatingInputStream(InputStream pStream,
MessageDigest pDigest)
Creates a new instance, which calculates a signature on the given stream,
using the given
MessageDigest . |
MessageDigestCalculatingInputStream(InputStream pStream,
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 |
---|---|
MessageDigest |
getMessageDigest()
Returns the
MessageDigest , which is being used for generating the
checksum. |
add, close, consume, getObservers, noteClosed, noteDataByte, noteDataBytes, noteError, noteFinished, read, read, read, remove, removeAllObservers
afterRead, available, beforeRead, handleIOException, mark, markSupported, reset, skip
public MessageDigestCalculatingInputStream(InputStream pStream, MessageDigest pDigest)
MessageDigest
.pStream
- the stream to calculate the message digest forpDigest
- the message digest to usepublic MessageDigestCalculatingInputStream(InputStream pStream, String pAlgorithm) throws NoSuchAlgorithmException
MessageDigest
with the given algorithm.pStream
- the stream to calculate the message digest forpAlgorithm
- the name of the algorithm to useNoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.public MessageDigestCalculatingInputStream(InputStream pStream) throws NoSuchAlgorithmException
MessageDigest
with the "MD5" algorithm.pStream
- 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()
.Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.