public class MessageDigestCalculatingInputStream extends ObservableInputStream
ObservableInputStream
. It creates its own ObservableInputStream.Observer
,
which calculates a checksum using a MessageDigest, for example an MD5 sum.
See the MessageDigest section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard algorithm names.
Note: Neither ObservableInputStream
, nor MessageDigest
, are thread safe. So is MessageDigestCalculatingInputStream
.
TODO Rename to MessageDigestInputStream in 3.0.
Modifier and Type | Class and Description |
---|---|
static class |
MessageDigestCalculatingInputStream.Builder
Builds a new
MessageDigestCalculatingInputStream instance. |
static class |
MessageDigestCalculatingInputStream.MessageDigestMaintainingObserver
Maintains the message digest.
|
ObservableInputStream.Observer
in
Constructor and Description |
---|
MessageDigestCalculatingInputStream(InputStream inputStream)
Deprecated.
Use
builder() . |
MessageDigestCalculatingInputStream(InputStream inputStream,
MessageDigest messageDigest)
Deprecated.
Use
builder() . |
MessageDigestCalculatingInputStream(InputStream inputStream,
String algorithm)
Deprecated.
Use
builder() . |
Modifier and Type | Method and Description |
---|---|
static MessageDigestCalculatingInputStream.Builder |
builder()
Constructs a new
MessageDigestCalculatingInputStream.Builder . |
MessageDigest |
getMessageDigest()
Gets 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
@Deprecated public MessageDigestCalculatingInputStream(InputStream inputStream) throws NoSuchAlgorithmException
builder()
.MessageDigest
with the "MD5" algorithm.
The MD5 algorithm is weak and should not be used.
inputStream
- the stream to calculate the message digest forNoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.@Deprecated public MessageDigestCalculatingInputStream(InputStream inputStream, MessageDigest messageDigest)
builder()
.MessageDigest
.inputStream
- the stream to calculate the message digest formessageDigest
- the message digest to use@Deprecated public MessageDigestCalculatingInputStream(InputStream inputStream, String algorithm) throws NoSuchAlgorithmException
builder()
.MessageDigest
with the given algorithm.inputStream
- the stream to calculate the message digest foralgorithm
- the name of the algorithm requested. See the MessageDigest section in the
Java Cryptography
Architecture Standard Algorithm Name Documentation for information about standard algorithm names.NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.public static MessageDigestCalculatingInputStream.Builder builder()
MessageDigestCalculatingInputStream.Builder
.MessageDigestCalculatingInputStream.Builder
.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–2023 The Apache Software Foundation. All rights reserved.