IoUtils { public static byte[] getChecksum(final InputStream in) throws IOException, NoSuchAlgorithmException { final MessageDigest checksumGenerator = MessageDigest.getInstance("MD5"); final DigestInputStream dis = new DigestInputStream(in, checksumGenerator); int readBytes = redirect(dis, new ByteArrayOutputStream()); logger.debug("{} byte(s) read", readBytes); return checksumGenerator.digest(); }  static void tryFlush(final Object... flushable); static int stream(final InputStream in, final StreamConsumer consumer); static int redirect(final InputStream from, final OutputStream to); static int redirect(final Reader from, final Writer to); static byte[] from(
      final InputStream in); static String from(
      final Reader reader); static byte[] getChecksum(final InputStream in); static String getChecksumAsString(final InputStream in);  }
@Test public void testGetChecksum() throws NoSuchAlgorithmException, IOException { final Object[][] testParameters = new Object[][] { {new ByteArrayInputStream(new byte[] {1, 2, 3}), new byte[] {82, -119, -33, 115, 125, -11, 115, 38, -4, -35, 34, 89, 122, -5, 31, -84}}, {new ByteArrayInputStream(new byte[] {4, 5, 6, 7, 8}), new byte[] {-94, -23, -23, -60, 5, -4, -76, 40, 8, -49, -96, -22, -14, 82, 124, 55}}, {new ByteArrayInputStream(new byte[] {9, 10, 11, 12, 13, 14, 15}), new byte[] {-80, -53, 24, -101, -113, 102, 100, 106, -112, 42, 57, -61, 15, 35, -61, -93}}}; for (final Object[] testParameter : testParameters) { byte[] expected = (byte[]) testParameter[1]; InputStream in = (InputStream) testParameter[0]; byte[] actual = IoUtils.getChecksum(in); for (int i = 0; i < actual.length; ++i) { assertEquals(expected[i], actual[i]); } } }