// Prepare the consumer
MessageDigest messageDigest;
try {
messageDigest = MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
throw new StLightException(e);
}
// Read the stream
try {
byte[] bytes = new byte[BUFFER_SIZE];
int len;
while ((len = in.read(bytes)) != -1) {
messageDigest.update(bytes, 0, len);
}
} catch (Exception e) {
throw new StLightException("Issue hashing the stream", e);
} finally {
// Close the source
try {
in.close();