Here you can find the source of calculateChecksum(InputStream is, String algorithm)
public static String calculateChecksum(InputStream is, String algorithm) throws NoSuchAlgorithmException, IOException
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import javax.xml.bind.DatatypeConverter; public class Main { /**// w w w .j av a2s.c o m * Calculates checksum, closing the inputstream in the end. */ public static String calculateChecksum(InputStream is, String algorithm) throws NoSuchAlgorithmException, IOException { MessageDigest digester = MessageDigest.getInstance(algorithm); try { byte[] block = new byte[4096]; int length; while ((length = is.read(block)) > 0) { digester.update(block, 0, length); } } finally { is.close(); } return DatatypeConverter.printHexBinary(digester.digest()); } }