Search in sources :

Example 76 with Checksum

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();
}
Also used : Checksum(java.util.zip.Checksum)

Example 77 with Checksum

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());
}
Also used : Checksum(java.util.zip.Checksum)

Example 78 with Checksum

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");
}
Also used : Checksum(java.util.zip.Checksum) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 79 with Checksum

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");
}
Also used : Checksum(java.util.zip.Checksum) Test(org.junit.jupiter.api.Test)

Example 80 with Checksum

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;
}
Also used : Checksum(java.util.zip.Checksum) Adler32(java.util.zip.Adler32)

Aggregations

Checksum (java.util.zip.Checksum)84 CRC32 (java.util.zip.CRC32)29 IOException (java.io.IOException)16 ByteBuffer (java.nio.ByteBuffer)15 Adler32 (java.util.zip.Adler32)12 File (java.io.File)8 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)6 Path (java.nio.file.Path)6 EOFException (java.io.EOFException)5 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5 CheckedInputStream (java.util.zip.CheckedInputStream)4 BufferedOutputStream (java.io.BufferedOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ArrayList (java.util.ArrayList)3 PureJavaCrc32 (org.apache.hadoop.util.PureJavaCrc32)3 BinaryInputArchive (org.apache.jute.BinaryInputArchive)3