Here you can find the source of SHA1(InputStream in)
public static byte[] SHA1(InputStream in) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.security.*; public class Main { private static final ThreadLocal<MessageDigest> sha1 = new ThreadLocal<MessageDigest>() { @Override/*from w w w.ja va 2s. com*/ protected MessageDigest initialValue() { MessageDigest crypt = null; try { crypt = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return crypt; } }; public static byte[] SHA1(InputStream in) throws IOException { MessageDigest crypt = sha1.get(); crypt.reset(); // Transfer bytes from in to out byte[] buf = new byte[4 * 1024]; int len; while ((len = in.read(buf)) > 0) { Thread.yield(); // out.write(buf, 0, len); crypt.update(buf, 0, len); } in.close(); return crypt.digest(); } public static byte[] SHA1(String fileName) throws IOException { MessageDigest crypt = sha1.get(); crypt.reset(); FileInputStream in = new FileInputStream(fileName); // Transfer bytes from in to out byte[] buf = new byte[4 * 1024]; int len; while ((len = in.read(buf)) > 0) { Thread.yield(); // out.write(buf, 0, len); crypt.update(buf, 0, len); } in.close(); return crypt.digest(); } public static byte[] SHA1(byte[] src) { MessageDigest crypt = sha1.get(); crypt.reset(); crypt.update(src); return crypt.digest(); } public static byte[] SHA1(byte[]... src1) { MessageDigest crypt = sha1.get(); crypt.reset(); for (int i = 0; i < src1.length; i++) { crypt.update(src1[i]); } return crypt.digest(); } }