private void checkLength(boolean eof) {
        if (eof) {
            if (dataLength != expectedLength) {
                throw new SdkClientException(
                        "Data read has a different length than the expected: "
                                + diagnosticInfo());
            }
        } else if (dataLength > expectedLength) {
            throw new SdkClientException("More data read than expected: "
                    + diagnosticInfo());
        }
    }
Checks the data length read so far against the expected total.

@param eof
           true if end of stream has been encountered; false otherwise

@throws SdkClientException
            if the data length read has exceeded the expected total, or
            if the total data length is not the same as the expected
            total.
aws-java-sdk-core/src/main/java/com/amazonaws/util/LengthCheckInputStream.java