public byte[] calcDigest(URL url) throws IOException { InputStream is = null; try { is = url.openStream(); return calcDigest(new BufferedInputStream(is, 1024 * 32)); } finally { if (is != null) { is.close(); } } }
public byte[] calcDigest(String source_str) { try { ByteArrayInputStream bs = new ByteArrayInputStream(source_str.getBytes()); return calcDigest(bs); } catch (IOException e) { throw new RuntimeException("IOException reading a byte array input stream, this should never happen", e); } }
public byte[] calcDigest(File file) throws IOException { FileInputStream is = null; try { is = new FileInputStream(file); return calcDigest(new BufferedInputStream(is, 1024 * 32)); } finally { if (is != null) { is.close(); } } }
/** * Calculates a digest for a given string. * * @param source_str the string whose contents will be used as the data to calculate the digest * * @return the string's digest * * @throws RuntimeException if a system error occurred - should never really happen */ public static byte[] getDigest(String source_str) { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigest(source_str); }
/** * Calculates the digest for a given file. The file's contents will be used as the source data for the digest calculation. * * @param file the file whose contents are to be used to calculate the digest. * * @return the file content's digest * * @throws IOException if the file could not be read or accessed */ public static byte[] getDigest(File file) throws IOException { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigest(file); }
public String calcDigestString(File file) throws IOException { return calculateDigestStringFromBytes(calcDigest(file)); }
public String calcDigestString(URL url) throws IOException { return calculateDigestStringFromBytes(calcDigest(url)); }
public String calcDigestString(String source_str) { return calculateDigestStringFromBytes(calcDigest(source_str)); }
/** * Returns the digest for the data found in the given stream. The digest is returned as a byte array; if you want * the digest as a String, call getDigestString methods instead. * * @param is the stream whose data is to be used to calculate the digest * * @return the stream data's hash * * @throws IOException if failed to read the stream for some reason */ public static byte[] getDigest(InputStream is) throws IOException { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigest(is); }