? MessageDigestCalculatingInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.io.input.ProxyInputStream
org.apache.commons.io.input.ObservableInputStream
org.apache.commons.io.input.MessageDigestCalculatingInputStream
- ????????:
Closeable
,AutoCloseable
This class is an example for using an
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
.-
?????
????????????static class
Maintains the message digest.????????/?? org.apache.commons.io.input.ObservableInputStream
ObservableInputStream.Observer
-
????
??????? java.io.FilterInputStream
in
-
?????
????????MessageDigestCalculatingInputStream
(InputStream inputStream) Creates a new instance, which calculates a signature on the given stream, using aMessageDigest
with the "MD5" algorithm.MessageDigestCalculatingInputStream
(InputStream inputStream, String algorithm) Creates a new instance, which calculates a signature on the given stream, using aMessageDigest
with the given algorithm.MessageDigestCalculatingInputStream
(InputStream inputStream, MessageDigest messageDigest) Creates a new instance, which calculates a signature on the given stream, using the givenMessageDigest
. -
????
??????? org.apache.commons.io.input.ObservableInputStream
add, close, consume, getObservers, noteClosed, noteDataByte, noteDataBytes, noteError, noteFinished, read, read, read, remove, removeAllObservers
??????? org.apache.commons.io.input.ProxyInputStream
afterRead, available, beforeRead, handleIOException, mark, markSupported, reset, skip
??????? java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
???????
-
MessageDigestCalculatingInputStream
Creates a new instance, which calculates a signature on the given stream, using the givenMessageDigest
.- ??:
inputStream
- the stream to calculate the message digest formessageDigest
- the message digest to use
-
MessageDigestCalculatingInputStream
public MessageDigestCalculatingInputStream(InputStream inputStream, String algorithm) throws NoSuchAlgorithmException Creates a new instance, which calculates a signature on the given stream, using aMessageDigest
with the given algorithm.- ??:
inputStream
- the stream to calculate the message digest foralgorithm
- the name of the algorithm to use- ??:
NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.
-
MessageDigestCalculatingInputStream
Creates a new instance, which calculates a signature on the given stream, using aMessageDigest
with the "MD5" algorithm.- ??:
inputStream
- the stream to calculate the message digest for- ??:
NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.
-
-
??????
-
getMessageDigest
Returns theMessageDigest
, 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 invokingObservableInputStream.consume()
.- ??:
- the message digest used
-