Class MessageDigestCalculatingInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
ObservableInputStream
. It creates its own ObservableInputStream.Observer
,
which calculates a checksum using a MessageDigest, for example an MD5 sum.
To build an instance, see MessageDigestCalculatingInputStream.Builder
.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builds a newMessageDigestCalculatingInputStream
instance.static class
Maintains the message digest.Nested classes/interfaces inherited from class org.apache.commons.io.input.ObservableInputStream
ObservableInputStream.Observer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
The default message digest algorithm.private final MessageDigest
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionMessageDigestCalculatingInputStream
(InputStream inputStream) Deprecated.MessageDigestCalculatingInputStream
(InputStream inputStream, String algorithm) MessageDigestCalculatingInputStream
(InputStream inputStream, MessageDigest messageDigest) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Constructs a newMessageDigestCalculatingInputStream.Builder
.(package private) static MessageDigest
Gets a MessageDigest object that implements the default digest algorithm.Gets theMessageDigest
, which is being used for generating the checksum.Methods inherited from class org.apache.commons.io.input.ObservableInputStream
add, close, consume, getObservers, noteClosed, noteDataByte, noteDataBytes, noteError, noteFinished, read, read, read, remove, removeAllObservers
Methods inherited from class org.apache.commons.io.input.ProxyInputStream
afterRead, available, beforeRead, handleIOException, mark, markSupported, reset, skip
-
Field Details
-
DEFAULT_ALGORITHM
The default message digest algorithm.The MD5 cryptographic algorithm is weak and should not be used.
- See Also:
-
messageDigest
-
-
Constructor Details
-
MessageDigestCalculatingInputStream
@Deprecated public MessageDigestCalculatingInputStream(InputStream inputStream) throws NoSuchAlgorithmException Deprecated.Creates a new instance, which calculates a signature on the given stream, using aMessageDigest
with the "MD5" algorithm.The MD5 algorithm is weak and should not be used.
- Parameters:
inputStream
- the stream to calculate the message digest for- Throws:
NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.
-
MessageDigestCalculatingInputStream
@Deprecated public MessageDigestCalculatingInputStream(InputStream inputStream, MessageDigest messageDigest) Deprecated.Creates a new instance, which calculates a signature on the given stream, using the givenMessageDigest
.- Parameters:
inputStream
- the stream to calculate the message digest formessageDigest
- the message digest to use
-
MessageDigestCalculatingInputStream
@Deprecated public MessageDigestCalculatingInputStream(InputStream inputStream, String algorithm) throws NoSuchAlgorithmException Deprecated.Creates a new instance, which calculates a signature on the given stream, using aMessageDigest
with the given algorithm.- Parameters:
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.- Throws:
NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.
-
-
Method Details
-
builder
Constructs a newMessageDigestCalculatingInputStream.Builder
.- Returns:
- a new
MessageDigestCalculatingInputStream.Builder
. - Since:
- 2.12.0
-
getDefaultMessageDigest
Gets a MessageDigest object that implements the default digest algorithm.- Returns:
- a Message Digest object that implements the default algorithm.
- Throws:
NoSuchAlgorithmException
- if no Provider supports a MessageDigestSpi implementation.- See Also:
-
getMessageDigest
Gets 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 invoking
ObservableInputStream.consume()
.- Returns:
- the message digest used
-
builder()
,MessageDigestCalculatingInputStream.Builder
, andMessageDigestCalculatingInputStream.Builder.get()
.