Class ByteUtil

java.lang.Object
io.permazen.util.ByteUtil

public final class ByteUtil extends Object
ByteData manipulation utilities.
  • Field Details

  • Method Details

    • min

      public static ByteData min(ByteData b1, ByteData b2)
      Determine the smaller of two byte strings when compared lexicographically using unsigned values.
      Parameters:
      b1 - first byte string
      b2 - second byte string
      Returns:
      b1 if b1 <= b2, otherwise b2
      Throws:
      NullPointerException - if b1 or b2 is null
    • max

      public static ByteData max(ByteData b1, ByteData b2)
      Determine the larger of two byte strings when compared lexicographically using unsigned values.
      Parameters:
      b1 - first byte string
      b2 - second byte string
      Returns:
      b1 if b1 >= b2, otherwise b2
      Throws:
      NullPointerException - if b1 or b2 is null
    • getNextKey

      public static ByteData getNextKey(ByteData key)
      Get the next key greater than the given key in unsigned lexicographic ordering.

      This creates a new key simply by appending a 0x00 byte to the data contained in the given key.

      Parameters:
      key - previous key
      Returns:
      next key after key
      Throws:
      NullPointerException - if key is null
    • isConsecutive

      public static boolean isConsecutive(ByteData key1, ByteData key2)
      Determine whether key2 is the next key after key1.
      Parameters:
      key1 - first key
      key2 - second key
      Returns:
      true if key2 immediately follows key1
      Throws:
      NullPointerException - if either parameter is null
    • getKeyAfterPrefix

      public static ByteData getKeyAfterPrefix(ByteData prefix)
      Get the first key that would be greater than the given key in unsigned lexicographic ordering and that does not have the given key as a prefix.
      Parameters:
      prefix - lower bound prefix key
      Returns:
      next key not having prefix as a prefix
      Throws:
      IllegalArgumentException - if prefix has zero length
      IllegalArgumentException - if prefix contains only 0xff bytes
      NullPointerException - if prefix is null
    • readInt

      public static int readInt(ByteData.Reader reader)
      Read an int as four big-endian bytes.
      Parameters:
      reader - input
      Returns:
      decoded integer
      Throws:
      IndexOutOfBoundsException - if less than four bytes remain in reader
      NullPointerException - if reader is null
      See Also:
    • writeInt

      public static void writeInt(ByteData.Writer writer, int value)
      Write an int as four big-endian bytes.
      Parameters:
      writer - byte destination
      value - value to write
      Throws:
      NullPointerException - if writer is null
      See Also:
    • readLong

      public static long readLong(ByteData.Reader reader)
      Read a long as eight big-endian bytes.
      Parameters:
      reader - input
      Returns:
      decoded long
      Throws:
      IndexOutOfBoundsException - if less than eight bytes remain in reader
      See Also:
    • writeLong

      public static void writeLong(ByteData.Writer writer, long value)
      Write a long as eight big-endian bytes.
      Parameters:
      writer - byte destination
      value - value to write
      Throws:
      NullPointerException - if writer is null
      See Also:
    • toString

      public static String toString(ByteData data)
      Convert byte data into a string of hex digits, or "null" for null..
      Parameters:
      data - byte data
      Returns:
      string encoding of data, or "null" if data is null
      See Also: