java.lang.Object
com.pnfsoftware.jeb.util.primitives.Bytes

public class Bytes extends Object
Utility methods for byte.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    equals(byte[] array1, byte[] array2)
    Compare byte arrays for equality.
    static boolean
    equals(byte[] array1, int pos1, byte[] array2, int pos2, int size)
    Compare byte-array ranges for equality.
    static int
    indexOf(byte[] array, byte[] target)
    Find the first occurrence of a sequence of bytes.
    static int
    indexOf(byte[] array, int from, byte[] target)
    Find the first occurrence of a sequence of bytes.
    static int
    indexOf(byte[] array, int from, int end, byte[] target, int targetFrom, int targetEnd, byte[] targetMask)
    Find the first occurrence of a sequence of bytes.
    static int
    lastIndexOf(byte[] array, byte[] target)
    Find the last occurrence of a sequence of bytes.
    static int
    lastIndexOf(byte[] array, int from, byte[] target)
    Find the last occurrence of a sequence of bytes.
    static int
    lastIndexOf(byte[] array, int from, byte[] target, byte[] targetMask)
    Find the last occurrence of a sequence of bytes.
    static String
    toUnsignedString(byte value)
    Convert a byte to its unsigned decimal string representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Bytes

      public Bytes()
  • Method Details

    • toUnsignedString

      public static String toUnsignedString(byte value)
      Convert a byte to its unsigned decimal string representation.
      Parameters:
      value - byte value
      Returns:
      the unsigned decimal representation of value
    • indexOf

      public static int indexOf(byte[] array, byte[] target)
      Find the first occurrence of a sequence of bytes.
      Parameters:
      array - array to be searched
      target - bytes to be found
      Returns:
      index >= 0, or -1 if not found
    • indexOf

      public static int indexOf(byte[] array, int from, byte[] target)
      Find the first occurrence of a sequence of bytes.
      Parameters:
      array - array to be searched
      from - start index in array
      target - bytes to be found
      Returns:
      index >= `from`, or -1 if not found
    • indexOf

      public static int indexOf(byte[] array, int from, int end, byte[] target, int targetFrom, int targetEnd, byte[] targetMask)
      Find the first occurrence of a sequence of bytes.
      Parameters:
      array - array to be searched
      from - start of search
      end - end of search (exclusive)
      target - bytes to be found
      targetFrom - actual first target byte in the target array
      targetEnd - actual end (exclusive) target byte in the target array
      targetMask - optional binary mask, must be the same length as the target if present; the indices targetFrom and targetEnd apply as well
      Returns:
      index >= from and < end, or -1 if not found
    • lastIndexOf

      public static int lastIndexOf(byte[] array, byte[] target)
      Find the last occurrence of a sequence of bytes.
      Parameters:
      array - array to be searched
      target - bytes to be found
      Returns:
      index >= 0, or -1 if not found
    • lastIndexOf

      public static int lastIndexOf(byte[] array, int from, byte[] target)
      Find the last occurrence of a sequence of bytes.
      Parameters:
      array - array to be searched
      from - will search backward from this index
      target - bytes to be found
      Returns:
      index <= from, or -1 if not found
    • lastIndexOf

      public static int lastIndexOf(byte[] array, int from, byte[] target, byte[] targetMask)
      Find the last occurrence of a sequence of bytes.
      Parameters:
      array - array to be searched
      from - will search backward from this index
      target - bytes to be found
      targetMask - optional binary mask, must be the same length as the target if present
      Returns:
      index <= from, or -1 if not found
    • equals

      public static boolean equals(byte[] array1, int pos1, byte[] array2, int pos2, int size)
      Compare byte-array ranges for equality.
      Parameters:
      array1 - first byte array
      pos1 - start offset in the first array
      array2 - second byte array
      pos2 - start offset in the second array
      size - number of bytes to compare
      Returns:
      true if the byte ranges are equal
    • equals

      public static boolean equals(byte[] array1, byte[] array2)
      Compare byte arrays for equality.
      Parameters:
      array1 - first byte array, may be null
      array2 - second byte array, may be null
      Returns:
      true if both arrays are null or contain the same bytes