Here you can find the source of digest(InputStream is, String digestAlgorithm)
Parameter | Description |
---|---|
is | a parameter |
digestAlgorithm | a parameter |
Parameter | Description |
---|---|
NoSuchAlgorithmException | an exception |
IOException | an exception |
private static byte[] digest(InputStream is, String digestAlgorithm) 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; public class Main { /**//from ww w .j av a2 s . c o m * * @param is * @param digestAlgorithm * @return a byte array with the calculated digest. * @throws NoSuchAlgorithmException * @throws IOException */ private static byte[] digest(InputStream is, String digestAlgorithm) throws NoSuchAlgorithmException, IOException { MessageDigest digestor = MessageDigest.getInstance(digestAlgorithm); // reads file in 1Mbyte chunks (1048576 bytes - 2^20 bytes) int bufSize = 1048576; // 1 MByte byte[] buffer = new byte[bufSize]; int n = is.read(buffer, 0, bufSize); while (n != -1) { digestor.update(buffer, 0, n); n = is.read(buffer, 0, bufSize); } is.close(); return digestor.digest(); } }