code: public void setDigest(String algorithm) {
          try {
              // Reuse extant digest if its sha1 algorithm.
              if (this.digest == null ||
                      !this.digest.getAlgorithm().equals(algorithm)) {
                  setDigest(MessageDigest.getInstance(algorithm));
              }
          } catch (NoSuchAlgorithmException e) {
              e.printStackTrace();
          }
      }
docs: Sets a digest function which may be applied to recorded data.
  The difference between calling this method and {@link #setDigest(MessageDigest)}
  is that this method tries to reuse MethodDigest instance if already allocated
  and of appropriate algorithm.
  @param algorithm Message digest algorithm to use.
  @see #setDigest(MessageDigest)