public final class DigestProvider
extends java.lang.Object
implements java.lang.Cloneable
DigestInputStream
and DigestOutputStream
using the specified algorithm.Constructor and Description |
---|
DigestProvider(java.lang.String algorithm)
Constructs a new digest provider with the specified algorithm.
|
DigestProvider(java.lang.String algorithm,
boolean shouldClone)
Constructs a new digest provider with the specified algorithm
and if the digest should be cloned for created streams.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clones this object.
|
boolean |
digestClonedForStreams()
Gets whether
MessageDigest s are cloned for streams. |
java.lang.String |
getAlgorithm()
Gets the algorithm of this provider.
|
java.security.DigestInputStream |
getDigestInputStream(java.io.InputStream inputStream)
Gets the digest input stream for this class.
|
byte[] |
getDigestOf(byte[] dataIn)
Gets the digest of the specified array.
|
java.security.DigestOutputStream |
getDigestOutputStream(java.io.OutputStream outputStream)
Gets the digest output stream for this class.
|
int |
getLength()
Gets the length of the algorithm in bytes.
|
static DigestProvider |
getMD5Instance(boolean shouldClone)
Gets the instance for MD5.
|
static DigestProvider |
getSHA1Instance(boolean shouldClone)
Gets the instance for SHA-1.
|
static DigestProvider |
getSHA256Instance(boolean shouldClone)
Gets the instance for SHA-256.
|
static DigestProvider |
getSHA512Instance(boolean shouldClone)
Gets the instance for SHA-512.
|
public DigestProvider(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- The algorithm of the digest.java.lang.NullPointerException
- algorithm is null.java.security.NoSuchAlgorithmException
- The algorithm does not exist.public DigestProvider(java.lang.String algorithm, boolean shouldClone) throws java.security.NoSuchAlgorithmException
algorithm
- The algorithm of the digest.shouldClone
- The digest should be cloned when creating streams.java.lang.NullPointerException
- algorithm is null.java.security.NoSuchAlgorithmException
- The algorithm does not exist.public java.security.DigestInputStream getDigestInputStream(java.io.InputStream inputStream)
digestClonedForStreams()
is false,
The current calculated digest for this stream changes for all the other streams.inputStream
- The input stream to get the digest for.public java.security.DigestOutputStream getDigestOutputStream(java.io.OutputStream outputStream)
digestClonedForStreams()
is false,
The current calculated digest for this stream changes for all the other streams.outputStream
- The output stream to get the digest for.public java.lang.String getAlgorithm()
public int getLength()
public boolean digestClonedForStreams()
MessageDigest
s are cloned for streams.public byte[] getDigestOf(byte[] dataIn)
digestClonedForStreams()
is false,
The current calculated digest for all these streams are reset.dataIn
- The byte array to find the digest of.public java.lang.Object clone()
clone
in class java.lang.Object
public static DigestProvider getMD5Instance(boolean shouldClone)
shouldClone
- The digest should be cloned when creating streams.public static DigestProvider getSHA1Instance(boolean shouldClone)
shouldClone
- The digest should be cloned when creating streams.public static DigestProvider getSHA256Instance(boolean shouldClone)
shouldClone
- The digest should be cloned when creating streams.public static DigestProvider getSHA512Instance(boolean shouldClone)
shouldClone
- The digest should be cloned when creating streams.