Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
clients/src/main/java/org/apache/kafka/common/utils/Checksums.java
  • Loading branch information
ijuma committed Aug 12, 2022
1 parent 26f8a89 commit 27cb7ad
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions clients/src/main/java/org/apache/kafka/common/utils/Checksums.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
package org.apache.kafka.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
Expand All @@ -35,17 +32,16 @@
* NOTE: This class is intended for INTERNAL usage only within Kafka.
*/
public final class Checksums {

private static final Logger log = LoggerFactory.getLogger(Checksums.class);
private static final MethodHandle BYTE_BUFFER_UPDATE;

static {
MethodHandle byteBufferUpdate = null;
if (Java.IS_JAVA9_COMPATIBLE) {
try {
byteBufferUpdate = MethodHandles.publicLookup().findVirtual(Checksum.class, "update", MethodType.methodType(void.class, ByteBuffer.class));
byteBufferUpdate = MethodHandles.publicLookup().findVirtual(Checksum.class, "update",
MethodType.methodType(void.class, ByteBuffer.class));
} catch (Throwable t) {
log.warn("Cannot uses java.util.zip.Checksum::update(ByteBuffer): direct ByteBuffers checksum won't use optimized platform support", t);
handleUpdateThrowable(t);
}
}
BYTE_BUFFER_UPDATE = byteBufferUpdate;
Expand All @@ -69,9 +65,7 @@ public static void update(Checksum checksum, ByteBuffer buffer, int length) {
public static void update(Checksum checksum, ByteBuffer buffer, int offset, int length) {
if (buffer.hasArray()) {
checksum.update(buffer.array(), buffer.position() + buffer.arrayOffset() + offset, length);
return;
}
if (BYTE_BUFFER_UPDATE != null && buffer.isDirect()) {
} else if (BYTE_BUFFER_UPDATE != null && buffer.isDirect()) {
final int oldPosition = buffer.position();
final int oldLimit = buffer.limit();
try {
Expand Down

0 comments on commit 27cb7ad

Please sign in to comment.