code: public static byte[] computeMD5Hash(InputStream is) throws IOException {
          BufferedInputStream bis = new BufferedInputStream(is);
          try {
              MessageDigest messageDigest = MessageDigest.getInstance("MD5");
              byte[] buffer = new byte[SIXTEEN_K];
              int bytesRead;
              while ( (bytesRead = bis.read(buffer, 0, buffer.length)) != -1 ) {
                  messageDigest.update(buffer, 0, bytesRead);
              }
              return messageDigest.digest();
          } catch (NoSuchAlgorithmException e) {
              // should never get here
              throw new IllegalStateException(e);
          } finally {
              try {
                  bis.close();
              } catch (Exception e) {
                  LogFactory.getLog(Md5Utils.class).debug(
                          "Unable to close input stream of hash candidate: " + e);
              }
          }
      }
docs: Computes the MD5 hash of the data in the given input stream and returns
  it as an array of bytes.
  Note this method closes the given input stream upon completion.