code: public static DigestInputStream wrapStream(InputStream inStream,
                                                 Algorithm algorithm) {
          MessageDigest streamDigest = null;
          try {
              streamDigest = MessageDigest.getInstance(algorithm.toString());
          } catch (NoSuchAlgorithmException e) {
              String error = "Could not create a MessageDigest because the " +
                             "required algorithm " + algorithm.toString() +
                             " is not supported.";
              throw new RuntimeException(error);
          }
  
          DigestInputStream wrappedContent =
              new DigestInputStream(inStream, streamDigest);
          return wrappedContent;
      }
docs: Wraps an InputStream with a DigestInputStream in order to compute
  a checksum as the stream is being read.
  
  @param inStream  The stream to wrap
  @param algorithm The algorithm used to compute the digest
  @return The original stream wrapped as a DigestInputStream