Class ByteArrayUtils

java.lang.Object
org.yamcs.utils.ByteArrayUtils

public class ByteArrayUtils extends Object
  • Field Details

    • EMPTY

      public static final byte[] EMPTY
  • Constructor Details

    • ByteArrayUtils

      public ByteArrayUtils()
  • Method Details

    • plusOne

      public static byte[] plusOne(byte[] a)
      If the array is considered binary representation of an integer, add 1 to the integer and returns the corresponding binary representation. In case an overflow is detected (if the initial array was all 0XFF) an IllegalArgumentException is thrown.
      Parameters:
      a -
      Returns:
      a+1
    • minusOne

      public static byte[] minusOne(byte[] a)
    • compare

      public static int compare(byte[] a1, byte[] a2)
      lexicographic comparison which returns 0 if one of the array is a subarray of the other one
      Parameters:
      a1 -
      a2 -
    • encodeLong

      public static byte[] encodeLong(long x, byte[] a, int offset)
      write an long into a byte array at offset and returns the array
    • encodeLongLE

      public static byte[] encodeLongLE(long x, byte[] a, int offset)
    • encodeLong

      public static byte[] encodeLong(long x)
      write a long into a byte array of 8 bytes
      Parameters:
      x -
      Returns:
    • encodeLongLE

      public static byte[] encodeLongLE(long x)
      write a long into a byte array of 8 bytes, in little endian
    • decodeLong

      public static long decodeLong(byte[] a, int offset)
    • decodeLongLE

      public static long decodeLongLE(byte[] a, int offset)
    • decodeUnsigned7Bytes

      public static long decodeUnsigned7Bytes(byte[] a, int offset)
    • encodeUnsigned6Bytes

      public static byte[] encodeUnsigned6Bytes(long x, byte[] a, int offset)
    • decodeUnsigned6Bytes

      public static long decodeUnsigned6Bytes(byte[] a, int offset)
      Decode 6 bytes as an unsigned integer
      Parameters:
      a -
      offset -
      Returns:
    • decode6Bytes

      public static long decode6Bytes(byte[] a, int offset)
      Decode 6 bytes as a signed integer in two's complement encoding
      Parameters:
      a -
      offset -
      Returns:
    • decode5Bytes

      public static long decode5Bytes(byte[] a, int offset)
      Decode 5 bytes as a signed integer in two's complement encoding
      Parameters:
      a -
      offset -
      Returns:
    • encodeUnsigned5Bytes

      public static byte[] encodeUnsigned5Bytes(long x, byte[] a, int offset)
    • decodeUnsigned5Bytes

      public static long decodeUnsigned5Bytes(byte[] a, int offset)
    • encodeInt

      public static byte[] encodeInt(int x, byte[] a, int offset)
      write an int into a byte array at offset and returns the array
    • encodeIntLE

      public static byte[] encodeIntLE(int x, byte[] a, int offset)
    • encodeUnsignedIntLE

      public static byte[] encodeUnsignedIntLE(long x, byte[] a, int offset)
    • encodeInt

      public static byte[] encodeInt(int x)
    • encodeIntLE

      public static byte[] encodeIntLE(int x)
    • decodeInt

      public static int decodeInt(byte[] a, int offset)
    • decodeIntLE

      public static int decodeIntLE(byte[] a, int offset)
    • decodeUnsignedIntLE

      public static long decodeUnsignedIntLE(byte[] a, int offset)
    • encodeUnsigned3Bytes

      public static byte[] encodeUnsigned3Bytes(int x, byte[] a, int offset)
    • decodeUnsigned3Bytes

      public static int decodeUnsigned3Bytes(byte[] a, int offset)
    • decodeUnsigned3BytesLE

      public static int decodeUnsigned3BytesLE(byte[] a, int offset)
    • encodeUnsignedShort

      public static byte[] encodeUnsignedShort(int x, byte[] a, int offset)
    • encodeUnsignedShort

      public static byte[] encodeUnsignedShort(int x)
    • encodeUnsignedShortLE

      public static byte[] encodeUnsignedShortLE(int x, byte[] a, int offset)
    • encodeUnsignedShortLE

      public static byte[] encodeUnsignedShortLE(int x)
    • decodeShort

      public static short decodeShort(byte[] a, int offset)
    • decodeShortLE

      public static short decodeShortLE(byte[] a, int offset)
    • decodeUnsignedShort

      public static int decodeUnsignedShort(byte[] a, int offset)
    • decodeUnsignedShortLE

      public static int decodeUnsignedShortLE(byte[] a, int offset)
      Decode unsigned short
      Parameters:
      a -
      offset -
      Returns:
    • encodeUnsignedByte

      public static byte[] encodeUnsignedByte(short x, byte[] a, int offset)
    • encodeByte

      public static byte[] encodeByte(short x, byte[] a, int offset)
    • decodeUnsignedByte

      public static short decodeUnsignedByte(byte[] a, int offset)
    • decodeByte

      public static byte decodeByte(byte[] a, int offset)