Search in sources :

Example 1 with CRC32MismatchException

use of com.qcloud.cos.exception.CRC32MismatchException in project cos-java-sdk-v5 by tencentyun.

the class Message method validateMessageCrc.

private static void validateMessageCrc(ByteBuffer buf, int totalLength) {
    Checksum crc = new CRC32();
    Checksums.update(crc, (ByteBuffer) buf.duplicate().limit(buf.position() + totalLength - 4));
    long computedMessageCrc = crc.getValue();
    long wireMessageCrc = Utils.toUnsignedLong(buf.getInt(buf.position() + totalLength - 4));
    if (wireMessageCrc != computedMessageCrc) {
        throw new CosClientException(new CRC32MismatchException(format("Message checksum failure: expected 0x%x, computed 0x%x", wireMessageCrc, computedMessageCrc)));
    }
}
Also used : CRC32(java.util.zip.CRC32) Checksum(java.util.zip.Checksum) CosClientException(com.qcloud.cos.exception.CosClientException) CRC32MismatchException(com.qcloud.cos.exception.CRC32MismatchException)

Aggregations

CRC32MismatchException (com.qcloud.cos.exception.CRC32MismatchException)1 CosClientException (com.qcloud.cos.exception.CosClientException)1 CRC32 (java.util.zip.CRC32)1 Checksum (java.util.zip.Checksum)1