ChecksumUtil { public static byte[] getChecksumBytes(DigestInputStream digestStream) { MessageDigest digest = digestStream.getMessageDigest(); return digest.digest(); } ChecksumUtil(Algorithm alg); String generateChecksum(File file); String generateChecksum(InputStream inStream); String generateChecksum(String string); String generateChecksumBase64(String string); static DigestInputStream wrapStream(InputStream inStream,
                                               Algorithm algorithm); static String getChecksum(DigestInputStream digestStream); static byte[] getChecksumBytes(DigestInputStream digestStream); static String checksumBytesToString(byte[] digestBytes); static byte[] hexStringToByteArray(String s); static String convertToBase64Encoding(String hexEncodedChecksum);  }
@Test public void testGetChecksumBytes() throws Exception { ChecksumUtil util = new ChecksumUtil(Algorithm.MD5); String md5 = util.generateChecksum(getStream(content)); DigestInputStream wrappedStream = ChecksumUtil.wrapStream(getStream(content), Algorithm.MD5); while (wrappedStream.read() > -1) { } byte[] checksumBytes = ChecksumUtil.getChecksumBytes(wrappedStream); String checksum = ChecksumUtil.checksumBytesToString(checksumBytes); assertEquals(md5, checksum); }