BufferChecksum implementation for use with
Lz4Compressor and Lz4Decompressor.
StreamingXXHash32#asChecksum() has a particularly nasty implementation
of Checksum#update(int) that allocates a single-element byte array for
every invocation.
In addition to that, it doesn't implement an overload that accepts a ByteBuffer
as an argument.
Combined, this means that we can't use ReflectiveByteBufChecksum at all,
and can't use SlowByteBufChecksum because of its atrocious performance
with direct byte buffers (allocating an array and making a JNI call for every byte
checksummed might be considered sub-optimal by some).
Block version of xxHash32 (XXHash32), however, does provide
XXHash32#hash(ByteBuffer, int) method that is efficient and does exactly
what we need, with a caveat that we can only invoke it once before having to reset.
This, however, is fine for our purposes, given the way we use it in
Lz4Compressor and Lz4Decompressor:
reset(), followed by one update(), followed by getValue().
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private boolean | |
| private int | |
| private static final XXHash32 |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public long | getValue()
Overrides io. Implements java. |
| public void | reset()
Overrides io. Implements java. |
| public void | update(int
the byte to update the checksum with b)Overrides io. Implements java. |
| public void | update(byte[]
the byte array to update the checksum with b, int the start offset of the data off, int the number of bytes to use for the update len)Overrides io. Implements java. |
| public void | update(ByteBuffer
the ByteBuffer to update the checksum with buffer)Overrides default java. |
| public void | update(Buffer b, int off, int len)
Overrides io. |
| seed | back to summary |
|---|---|
| private final int seed | |
| used | back to summary |
|---|---|
| private boolean used | |
| value | back to summary |
|---|---|
| private int value | |
| XXHASH32 | back to summary |
|---|---|
| private static final XXHash32 XXHASH32 | |
| Lz4XXHash32 | back to summary |
|---|---|
public Lz4XXHash32(int seed)
| |
| checkUsed | back to summary |
|---|---|
| private void checkUsed() | |
| getValue | back to summary |
|---|---|
| public long getValue() Overrides io. Implements java. Doc from java. Returns the current checksum value.
| |
| reset | back to summary |
|---|---|
| public void reset() Overrides io. Implements java. Doc from java. Resets the checksum to its initial value.
| |
| update | back to summary |
|---|---|
| public void update(int b) Overrides io. Implements java. Doc from java. Updates the current checksum with the specified byte.
| |
| update | back to summary |
|---|---|
| public void update(byte[] b, int off, int len) Overrides io. Implements java. Doc from java. Updates the current checksum with the specified array of bytes.
| |
| update | back to summary |
|---|---|
| public void update(ByteBuffer buffer) Overrides default java. Doc from java. Updates the current checksum with the bytes from the specified buffer. The checksum is updated with the remaining bytes in the buffer, starting at the buffer's position. Upon return, the buffer's position will be updated to its limit; its limit will not have been changed.
| |
| update | back to summary |
|---|---|
| public void update(Buffer b, int off, int len) Overrides io.
| |