public static String copyAndDigest(InputStream inputStream, OutputStream outputStream) throws IOException, NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    byte[] buffer = new byte[65536];
    try
    {
      int read = inputStream.read(buffer);
      while (read >= 1) {
        digest.update(buffer, 0, read);
        outputStream.write(buffer, 0, read);
        read = inputStream.read(buffer);
      }
    } finally {
      closeSilently(inputStream);
      closeSilently(outputStream);
    }

    return String.format("%1$032x", new Object[] { new BigInteger(1, digest.digest()) });
  }