/** * Check that the digest computed from the representation content and the * digest declared by the representation are the same.<br> * Since this method relies on the {@link #computeDigest(String)} method, * and since this method reads entirely the representation's stream, user * must take care of the content of the representation in case the latter is * transient. * * {@link #isTransient} * * @return True if both digests are not null and equals. */ public boolean checkDigest() { Digest digest = getDigest(); return (digest != null && digest.equals(getComputedDigest())); }
/** * Check that the digest computed from the representation content and the * digest declared by the representation are the same. It also first checks * that the algorithms are the same.<br> * Since this method relies on the {@link #computeDigest(String)} method, * and since this method reads entirely the representation's stream, user * must take care of the content of the representation in case the latter is * transient. * * {@link #isTransient} * * @param algorithm * The algorithm used to compute the digest to compare with. See * constant values in {@link org.restlet.data.Digest}. * @return True if both digests are not null and equals. */ public boolean checkDigest(String algorithm) { boolean result = false; if (this.algorithm != null && this.algorithm.equals(algorithm)) { result = checkDigest(); } else { Digest digest = getDigest(); if (digest != null) { if (algorithm.equals(digest.getAlgorithm())) { result = digest.equals(computeDigest(algorithm)); } } } return result; }