Class Bytes
java.lang.Object
org.apache.kafka.common.utils.Bytes
- All Implemented Interfaces:
Comparable<Bytes>
An immutable wrapper for a byte array.
This class provides a convenient way to work with byte arrays in Kafka APIs,
particularly in Kafka Streams state stores and serialization. It implements
Comparable to enable ordering of byte arrays.
The class caches the hashCode for improved performance when used as keys in hash-based data structures.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated, for removal: This API element is subject to removal in a future version.This interface is not part of the public API and will be removed in version 5.0. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Bytes.ByteArrayComparatorDeprecated, for removal: This API element is subject to removal in a future version.This field is not part of the public API and will be removed in version 5.0.static final byte[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleanbyte[]get()Get the data from the Bytes.inthashCode()The hashcode is cached except for the case where it is computed as 0, in which case we compute the hashcode on every call.static BytesDeprecated, for removal: This API element is subject to removal in a future version.This method is not part of the public API and will be removed in version 5.0.toString()static Byteswrap(byte[] bytes) Creates a Bytes instance wrapping the given byte array.
-
Field Details
-
EMPTY
public static final byte[] EMPTY -
BYTES_LEXICO_COMPARATOR
@Deprecated(since="4.3", forRemoval=true) public static final Bytes.ByteArrayComparator BYTES_LEXICO_COMPARATORDeprecated, for removal: This API element is subject to removal in a future version.This field is not part of the public API and will be removed in version 5.0. Internal Kafka code should useBytesUtils.BYTES_LEXICO_COMPARATORinstead.A byte array comparator based on lexicographic ordering.
-
-
Constructor Details
-
Bytes
public Bytes(byte[] bytes) Create a Bytes using the byte array.- Parameters:
bytes- This array becomes the backing storage for the object.- Throws:
NullPointerException- if bytes is null
-
-
Method Details
-
wrap
Creates a Bytes instance wrapping the given byte array.The provided array becomes the backing storage for the object.
- Parameters:
bytes- the byte array to wrap, or null- Returns:
- a new Bytes instance, or null if the input is null
-
get
public byte[] get()Get the data from the Bytes.- Returns:
- The underlying byte array
-
hashCode
-
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<Bytes>
-
toString
-
increment
@Deprecated(since="4.3", forRemoval=true) public static Bytes increment(Bytes input) throws IndexOutOfBoundsException Deprecated, for removal: This API element is subject to removal in a future version.This method is not part of the public API and will be removed in version 5.0. Internal Kafka code should useBytesUtils.increment(Bytes)instead.Increment the underlying byte array by adding 1.- Parameters:
input- - The byte array to increment- Returns:
- A new copy of the incremented byte array.
- Throws:
IndexOutOfBoundsException- if incrementing causes the underlying input byte array to overflow.
-