use of java.util.zip.Checksum in project kafka by apache.
the class Crc32C method compute.
/**
* Compute the CRC32C (Castagnoli) of the segment of the byte array given by the specified size and offset
*
* @param bytes The bytes to checksum
* @param offset the offset at which to begin the checksum computation
* @param size the number of bytes to checksum
* @return The CRC32C
*/
public static long compute(byte[] bytes, int offset, int size) {
Checksum crc = create();
crc.update(bytes, offset, size);
return crc.getValue();
}
use of java.util.zip.Checksum in project kafka by apache.
the class ChecksumsTest method doTestUpdateByteBuffer.
private void doTestUpdateByteBuffer(byte[] bytes, ByteBuffer buffer) {
buffer.put(bytes);
buffer.flip();
Checksum bufferCrc = Crc32C.create();
Checksums.update(bufferCrc, buffer, buffer.remaining());
assertEquals(Crc32C.compute(bytes, 0, bytes.length), bufferCrc.getValue());
assertEquals(0, buffer.position());
}
use of java.util.zip.Checksum in project kafka by apache.
the class ChecksumsTest method testUpdateInt.
@Test
public void testUpdateInt() {
final int value = 1000;
final ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.putInt(value);
Checksum crc1 = Crc32C.create();
Checksum crc2 = Crc32C.create();
Checksums.updateInt(crc1, value);
crc2.update(buffer.array(), buffer.arrayOffset(), 4);
assertEquals(crc1.getValue(), crc2.getValue(), "Crc values should be the same");
}
use of java.util.zip.Checksum in project kafka by apache.
the class Crc32CTest method testUpdate.
@Test
public void testUpdate() {
final byte[] bytes = "Any String you want".getBytes();
final int len = bytes.length;
Checksum crc1 = Crc32C.create();
Checksum crc2 = Crc32C.create();
Checksum crc3 = Crc32C.create();
crc1.update(bytes, 0, len);
for (int i = 0; i < len; i++) crc2.update(bytes[i]);
crc3.update(bytes, 0, len / 2);
crc3.update(bytes, len / 2, len - len / 2);
assertEquals(crc1.getValue(), crc2.getValue(), "Crc values should be the same");
assertEquals(crc1.getValue(), crc3.getValue(), "Crc values should be the same");
}
use of java.util.zip.Checksum in project iris by chicc999.
the class Message method getBodyCRC.
public long getBodyCRC() {
if (bodyCRC == 0) {
if (body != null && body.length > 0) {
Checksum checksum = new Adler32();
checksum.update(body, 0, body.length);
bodyCRC = checksum.getValue();
}
}
return bodyCRC;
}
Aggregations