Streams { public static String getMd5Checksum(InputStream in) { MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw Exceptions.propagate(e); } DigestInputStream dis = new DigestInputStream(in, md); readFullyAndClose(dis); byte[] digest = md.digest(); StringBuilder result = new StringBuilder(); for (byte b: digest) { result.append(Strings.padStart(Integer.toHexString((256+b)%256), 2, '0')); } return result.toString().toUpperCase(); }  @Beta static void closeQuietly(Closeable x); static InputStream newInputStreamWithContents(String contents); static Reader newReaderWithContents(String contents); static Reader reader(InputStream stream); static Reader reader(InputStream stream, Charset charset); static byte[] readFully(InputStream is); static int readFully(InputStream s, byte[] buf); static byte[] readFullyAndClose(InputStream is); static String readFullyString(InputStream is); static String readFullyStringAndClose(InputStream is); static String readFully(Reader is); static String readFullyAndClose(Reader is); static void copy(InputStream input, OutputStream output); static void copyClose(InputStream input, OutputStream output); static void copy(Reader input, Writer output); static Supplier<Integer> sizeSupplier(final ByteArrayOutputStream src); static Function<ByteArrayOutputStream,Integer> sizeFunction(); static ByteArrayOutputStream byteArrayOfString(String in); static ByteArrayOutputStream byteArray(byte[] in); static boolean logStreamTail(Logger log, String message, ByteArrayOutputStream stream, int max); static String getMd5Checksum(InputStream in); static boolean compare(InputStream s1, InputStream s2);  }
@Test public void testChecksum() { Assert.assertEquals(Streams.getMd5Checksum(new ByteArrayInputStream("hello world".getBytes())), "5EB63BBBE01EEED093CB22BB8F5ACDC3" ); }