Class ByteKey

java.lang.Object
org.apache.beam.sdk.io.range.ByteKey
All Implemented Interfaces:
Serializable, Comparable<ByteKey>

public final class ByteKey extends Object implements Comparable<ByteKey>, Serializable
A class representing a key consisting of an array of bytes. Arbitrary-length byte[] keys are typical in key-value stores such as Google Cloud Bigtable.

Instances of ByteKey are immutable.

ByteKey implements Comparable<ByteKey> by comparing the arrays in lexicographic order. The smallest ByteKey is a zero-length array; the successor to a key is the same key with an additional 0 byte appended; and keys have unbounded size.

Note that the empty ByteKey compares smaller than all other keys, but some systems have the semantic that when an empty ByteKey is used as an upper bound, it represents the largest possible key. In these cases, implementors should use isEmpty() to test whether an upper bound key is empty.

See Also:
  • Field Details

    • EMPTY

      public static final ByteKey EMPTY
      An empty key.
  • Method Details

    • copyFrom

      public static ByteKey copyFrom(ByteBuffer value)
      Creates a new ByteKey backed by a copy of the data remaining in the specified ByteBuffer.
    • copyFrom

      public static ByteKey copyFrom(byte[] bytes)
      Creates a new ByteKey backed by a copy of the specified byte[].

      Makes a copy of the underlying array.

    • of

      public static ByteKey of(int... bytes)
      Creates a new ByteKey backed by a copy of the specified int[]. This method is primarily used as a convenience to create a ByteKey in code without casting down to signed Java bytes:
      
       ByteKey key = ByteKey.of(0xde, 0xad, 0xbe, 0xef);
       

      Makes a copy of the input.

    • getValue

      public ByteBuffer getValue()
      Returns a read-only ByteBuffer representing this ByteKey.
    • getBytes

      public byte[] getBytes()
      Returns a newly-allocated byte[] representing this ByteKey.

      Copies the underlying byte[].

    • isEmpty

      public boolean isEmpty()
      Returns true if the byte[] backing this ByteKey is of length 0.
    • compareTo

      public int compareTo(@Nonnull ByteKey other)
      ByteKey implements Comparable<ByteKey> by comparing the arrays in lexicographic order. The smallest ByteKey is a zero-length array; the successor to a key is the same key with an additional 0 byte appended; and keys have unbounded size.
      Specified by:
      compareTo in interface Comparable<ByteKey>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object