ByteBufChecksum Class — netty Architecture
Architecture documentation for the ByteBufChecksum class in ByteBufChecksum.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 18dbf02c_fcee_6c04_8488_412942c3839e["ByteBufChecksum"] 2d513a28_c39a_3fc7_b9af_48d8fff5734f["ByteBufChecksum.java"] 18dbf02c_fcee_6c04_8488_412942c3839e -->|defined in| 2d513a28_c39a_3fc7_b9af_48d8fff5734f f64f60af_7fb2_d19a_5e75_517261a97cdc["ByteBufChecksum()"] 18dbf02c_fcee_6c04_8488_412942c3839e -->|method| f64f60af_7fb2_d19a_5e75_517261a97cdc 9d535c95_3969_d892_6cee_eff15adf97d7["update()"] 18dbf02c_fcee_6c04_8488_412942c3839e -->|method| 9d535c95_3969_d892_6cee_eff15adf97d7
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/ByteBufChecksum.java lines 34–120
abstract class ByteBufChecksum implements Checksum {
private final ByteProcessor updateProcessor = new ByteProcessor() {
@Override
public boolean process(byte value) throws Exception {
update(value);
return true;
}
};
static ByteBufChecksum wrapChecksum(Checksum checksum) {
ObjectUtil.checkNotNull(checksum, "checksum");
if (checksum instanceof ByteBufChecksum) {
return (ByteBufChecksum) checksum;
}
return new JdkByteBufChecksum(checksum);
}
/**
* @see #update(byte[], int, int)
*/
public void update(ByteBuf b, int off, int len) {
if (b.hasArray()) {
update(b.array(), b.arrayOffset() + off, len);
} else {
b.forEachByte(off, len, updateProcessor);
}
}
private static class JdkByteBufChecksum extends ByteBufChecksum {
protected final Checksum checksum;
private byte[] scratchBuffer;
JdkByteBufChecksum(Checksum checksum) {
this.checksum = checksum;
}
@Override
public void update(int b) {
checksum.update(b);
}
@Override
public void update(ByteBuf b, int off, int len) {
if (b.hasArray()) {
update(b.array(), b.arrayOffset() + off, len);
} else if (checksum instanceof CRC32) {
ByteBuffer byteBuffer = getSafeBuffer(b, off, len);
((CRC32) checksum).update(byteBuffer);
} else if (checksum instanceof Adler32) {
ByteBuffer byteBuffer = getSafeBuffer(b, off, len);
((Adler32) checksum).update(byteBuffer);
} else {
super.update(b, off, len);
}
}
private ByteBuffer getSafeBuffer(ByteBuf b, int off, int len) {
ByteBuffer byteBuffer = CompressionUtil.safeNioBuffer(b, off, len);
int javaVersion = PlatformDependent.javaVersion();
if (javaVersion >= 22 && javaVersion < 25 && byteBuffer.isDirect()) {
// Work-around for https://bugs.openjdk.org/browse/JDK-8357145
if (scratchBuffer == null || scratchBuffer.length < len) {
scratchBuffer = new byte[len];
}
ByteBuffer copy = ByteBuffer.wrap(scratchBuffer, 0, len);
copy.put(byteBuffer).flip();
return copy;
}
return byteBuffer;
}
@Override
public void update(byte[] b, int off, int len) {
checksum.update(b, off, len);
}
@Override
public long getValue() {
return checksum.getValue();
}
Source
Frequently Asked Questions
What is the ByteBufChecksum class?
ByteBufChecksum is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ByteBufChecksum.java.
Where is ByteBufChecksum defined?
ByteBufChecksum is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ByteBufChecksum.java at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free