code: public static byte[] dgst(InputStream is, Digest digest) throws IOException {
          checkNotNull(is);
          int n = 0;
          byte[] buffer = new byte[BUFFER_SIZE];
          while (n >= 0) {
              n = is.read(buffer);
              if (n > 0) {
                  digest.update(buffer, 0, n);
              }
          }
          byte[] result = new byte[digest.getDigestSize()];
          digest.doFinal(result, 0);
          return result;
      }
docs: Calculates digest and returns the value as a byte[].
  
  @param is     input stream
  @param digest digest algorithm
  @return digest as a byte[]
  @throws IOException On error reading from the stream.