private void validateMD5Digest() {
        /*
         * Some InputStream readers (e.g., java.util.Properties) read more than
         * once at the end of the stream. This class validates the digest once
         * -1 has been read so we must not validate twice.
         */
        if (expectedHash != null && !digestValidated ) {
            digestValidated = true;
            if (!Arrays.equals(digest.digest(), expectedHash)) {
                throw new SdkClientException("Unable to verify integrity of data download.  "
                        + "Client calculated content hash didn't match hash calculated by Amazon S3.  "
                        + "The data may be corrupt.");
            }
        }
    }
@see java.io.InputStream#read(byte[], int, int)
aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/internal/DigestValidationInputStream.java