use of com.ms.silverking.cloud.dht.client.impl.Checksum in project SilverKing by Morgan-Stanley.
the class ValueUtil method verifyChecksum.
public static void verifyChecksum(byte[] storedValue, int storedOffset, byte[] value, int valueOffset, int valueLength) throws CorruptValueException {
byte[] expectedChecksum;
byte[] actualChecksum;
ChecksumType checksumType;
Checksum checksum;
if (debugChecksum) {
System.out.println("storedValue: " + StringUtil.byteArrayToHexString(storedValue));
}
checksumType = MetaDataUtil.getChecksumType(storedValue, storedOffset);
if (checksumType != ChecksumType.NONE) {
actualChecksum = MetaDataUtil.getChecksum(storedValue, storedOffset);
checksum = ChecksumProvider.getChecksum(checksumType);
if (!checksum.isEmpty(actualChecksum)) {
expectedChecksum = checksum.checksum(value, valueOffset, valueLength);
if (debugChecksum) {
System.out.println("valueOffset: " + valueOffset);
System.out.println("valueLength: " + valueLength);
System.out.println("value: " + StringUtil.byteArrayToHexString(value, valueOffset, valueLength) + "\t" + valueLength);
System.out.println("value: " + new String(value, valueOffset, valueLength));
System.out.println("expectedChecksum: " + StringUtil.byteArrayToHexString(expectedChecksum));
System.out.println("actualChecksum: " + StringUtil.byteArrayToHexString(actualChecksum));
System.out.flush();
}
if (!Arrays.equals(expectedChecksum, actualChecksum)) {
throw new CorruptValueException(StringUtil.byteArrayToHexString(actualChecksum) + " != " + StringUtil.byteArrayToHexString(expectedChecksum));
}
}
}
}
Aggregations