Package org.duracloud.common.util
Class ChecksumUtil
java.lang.Object
org.duracloud.common.util.ChecksumUtil
A utility class for generating checksums. Beware this class it not threadsafe.
- Author:
- Daniel Bernstein
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThis class encapsulates the valid values for checksum algorithms. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringchecksumBytesToString(byte[] digestBytes) Converts a message digest byte array into a String based on the hex values appearing in the array.static StringconvertToBase64Encoding(String hexEncodedChecksum) Converts a hex-encoded checksum (like that produced by the getChecksum and generateChecksum methods of this class) to a base64-encoded checksumgenerateChecksum(File file) generateChecksum(InputStream inStream) This method generates checksum of content in arg stream.generateChecksum(String string) This method generates the checksum of a String and returns a hex-encoded String as the checksum valuegenerateChecksumBase64(String string) This method generates the checksum of a String and returns a base64-encoded String as the checksum valuestatic StringgetChecksum(DigestInputStream digestStream) Determines the checksum value of a DigestInputStream's underlying stream after the stream has been read.static byte[]getChecksumBytes(DigestInputStream digestStream) Determines the checksum value of a DigestInputStream's underlying stream after the stream has been read.static byte[]static DigestInputStreamwrapStream(InputStream inStream, ChecksumUtil.Algorithm algorithm) Wraps an InputStream with a DigestInputStream in order to compute a checksum as the stream is being read.
-
Constructor Details
-
ChecksumUtil
-
-
Method Details
-
generateChecksum
- Throws:
IOException
-
generateChecksum
This method generates checksum of content in arg stream. Warning: this method is NOT threadsafe.- Parameters:
inStream- Content used as target of checksum.- Returns:
- string representation of the generated checksum.
-
generateChecksum
This method generates the checksum of a String and returns a hex-encoded String as the checksum value- Parameters:
string- Content used as target of checksum.- Returns:
- string representation of the generated checksum using hex encoding
-
generateChecksumBase64
This method generates the checksum of a String and returns a base64-encoded String as the checksum value- Parameters:
string- Content used as target of checksum.- Returns:
- string representation of the generated checksum using base64 encoding
-
wrapStream
Wraps an InputStream with a DigestInputStream in order to compute a checksum as the stream is being read.- Parameters:
inStream- The stream to wrapalgorithm- The algorithm used to compute the digest- Returns:
- The original stream wrapped as a DigestInputStream
-
getChecksum
Determines the checksum value of a DigestInputStream's underlying stream after the stream has been read.- Parameters:
digestStream-- Returns:
- The checksum value of the stream's contents
-
getChecksumBytes
Determines the checksum value of a DigestInputStream's underlying stream after the stream has been read.- Parameters:
digestStream-- Returns:
- The checksum value of the stream's contents
-
checksumBytesToString
Converts a message digest byte array into a String based on the hex values appearing in the array. -
hexStringToByteArray
-
convertToBase64Encoding
Converts a hex-encoded checksum (like that produced by the getChecksum and generateChecksum methods of this class) to a base64-encoded checksum- Parameters:
hexEncodedChecksum- hex-encoded checksum- Returns:
- base64-encoded checksum
-