siddharthaDevineni commented on code in PR #21601:
URL: https://github.com/apache/kafka/pull/21601#discussion_r2874693786


##########
clients/src/main/java/org/apache/kafka/common/utils/Bytes.java:
##########
@@ -146,57 +163,36 @@ private static String toString(final byte[] b, int off, 
int len) {
      *
      * @param input - The byte array to increment
      * @return A new copy of the incremented byte array.
+     * @deprecated This method is not part of the public API and will be 
removed in version 5.0.
+     *             Internal Kafka code should use {@link 
org.apache.kafka.common.utils.internals.BytesUtils#increment(Bytes)} instead.
      */
+    @Deprecated(since = "4.3", forRemoval = true)
     public static Bytes increment(Bytes input) throws 
IndexOutOfBoundsException {
-        byte[] inputArr = input.get();
-        byte[] ret = new byte[inputArr.length];
-        int carry = 1;
-        for (int i = inputArr.length - 1; i >= 0; i--) {
-            if (inputArr[i] == (byte) 0xFF && carry == 1) {
-                ret[i] = (byte) 0x00;
-            } else {
-                ret[i] = (byte) (inputArr[i] + carry);
-                carry = 0;
-            }
-        }
-        if (carry == 0) {
-            return wrap(ret);
-        } else {
-            throw new IndexOutOfBoundsException();
-        }
+        return BytesUtils.increment(input);
     }
 
     /**
      * A byte array comparator based on lexicograpic ordering.
+     * @deprecated This field is not part of the public API and will be 
removed in version 5.0.
+     *             Internal Kafka code should use {@link 
org.apache.kafka.common.utils.internals.BytesUtils#BYTES_LEXICO_COMPARATOR} 
instead.
      */
+    @Deprecated(since = "4.3", forRemoval = true)
     public static final ByteArrayComparator BYTES_LEXICO_COMPARATOR = new 
LexicographicByteArrayComparator();
 
+    /**
+     * A byte array comparator interface.
+     *
+     * @deprecated This interface is not part of the public API and will be 
removed in version 5.0.
+     *             Internal Kafka code should use {@link 
org.apache.kafka.common.utils.internals.BytesUtils.ByteArrayComparator} instead.
+     */
+    @Deprecated(since = "4.3", forRemoval = true)
     public interface ByteArrayComparator extends Comparator<byte[]>, 
Serializable {
 
         int compare(final byte[] buffer1, int offset1, int length1,
                     final byte[] buffer2, int offset2, int length2);
     }
 
-    private static class LexicographicByteArrayComparator implements 
ByteArrayComparator {
-
-        @Override
-        public int compare(byte[] buffer1, byte[] buffer2) {
-            return compare(buffer1, 0, buffer1.length, buffer2, 0, 
buffer2.length);
-        }
-
-        public int compare(final byte[] buffer1, int offset1, int length1,
-                           final byte[] buffer2, int offset2, int length2) {
-
-            // short circuit equal case
-            if (buffer1 == buffer2 &&
-                    offset1 == offset2 &&
-                    length1 == length2) {
-                return 0;
-            }
-
-            int end1 = offset1 + length1;
-            int end2 = offset2 + length2;
-            return Arrays.compareUnsigned(buffer1, offset1, end1, buffer2, 
offset2, end2);
-        }
+    private static class LexicographicByteArrayComparator extends 
BytesUtils.LexicographicByteArrayComparator implements ByteArrayComparator {
+        // Empty - inherits implementation from BytesUtils, but explicitly 
declares it implements the local interface

Review Comment:
   fixed



##########
clients/src/main/java/org/apache/kafka/common/utils/internals/BytesUtils.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.common.utils.internals;
+
+import org.apache.kafka.common.utils.Bytes;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Comparator;
+
+/**
+ * Internal utility class for Bytes-related operations.
+ * This class is for internal Kafka use only and is not part of the public API.
+ */
+public final class BytesUtils {
+
+    private BytesUtils() {
+        // Utility class, prevent instantiation
+    }
+
+    /**
+     * Increment the underlying byte array by adding 1. Throws an 
IndexOutOfBoundsException if incrementing would cause
+     * the underlying input byte array to overflow.
+     *
+     * @param input - The byte array to increment
+     * @return A new copy of the incremented byte array.
+     */
+    public static Bytes increment(Bytes input) throws 
IndexOutOfBoundsException {
+        byte[] inputArr = input.get();
+        byte[] ret = new byte[inputArr.length];
+        int carry = 1;
+        for (int i = inputArr.length - 1; i >= 0; i--) {
+            if (inputArr[i] == (byte) 0xFF && carry == 1) {
+                ret[i] = (byte) 0x00;
+            } else {
+                ret[i] = (byte) (inputArr[i] + carry);
+                carry = 0;
+            }
+        }
+        if (carry == 0) {
+            return Bytes.wrap(ret);
+        } else {
+            throw new IndexOutOfBoundsException();
+        }
+    }
+
+    /**
+     * A byte array comparator based on lexicograpic ordering.

Review Comment:
   fixed



##########
clients/src/main/java/org/apache/kafka/common/utils/Bytes.java:
##########
@@ -146,57 +163,36 @@ private static String toString(final byte[] b, int off, 
int len) {
      *
      * @param input - The byte array to increment
      * @return A new copy of the incremented byte array.
+     * @deprecated This method is not part of the public API and will be 
removed in version 5.0.
+     *             Internal Kafka code should use {@link 
org.apache.kafka.common.utils.internals.BytesUtils#increment(Bytes)} instead.
      */
+    @Deprecated(since = "4.3", forRemoval = true)
     public static Bytes increment(Bytes input) throws 
IndexOutOfBoundsException {
-        byte[] inputArr = input.get();
-        byte[] ret = new byte[inputArr.length];
-        int carry = 1;
-        for (int i = inputArr.length - 1; i >= 0; i--) {
-            if (inputArr[i] == (byte) 0xFF && carry == 1) {
-                ret[i] = (byte) 0x00;
-            } else {
-                ret[i] = (byte) (inputArr[i] + carry);
-                carry = 0;
-            }
-        }
-        if (carry == 0) {
-            return wrap(ret);
-        } else {
-            throw new IndexOutOfBoundsException();
-        }
+        return BytesUtils.increment(input);
     }
 
     /**
      * A byte array comparator based on lexicograpic ordering.

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to