Class ByteArrayUtils

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

public class ByteArrayUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    compare(byte[] a1, byte[] a2)
    lexicographic comparison which returns 0 if one of the array is a subarray of the other one
    static long
    decode5Bytes(byte[] a, int offset)
    Decode 5 bytes as a signed integer in two's complement encoding
    static long
    decode6Bytes(byte[] a, int offset)
    Decode 6 bytes as a signed integer in two's complement encoding
    static int
    decodeInt(byte[] a, int offset)
     
    static int
    decodeIntLE(byte[] a, int offset)
     
    static long
    decodeLong(byte[] a, int offset)
     
    static long
    decodeLongLE(byte[] a, int offset)
     
    static short
    decodeShort(byte[] a, int offset)
     
    static int
    decodeUnsigned3Bytes(byte[] a, int offset)
     
    static int
    decodeUnsigned3BytesLE(byte[] a, int offset)
     
    static long
    decodeUnsigned5Bytes(byte[] a, int offset)
     
    static long
    decodeUnsigned6Bytes(byte[] a, int offset)
    Decode 6 bytes as an unsigned integer
    static long
    decodeUnsigned7Bytes(byte[] a, int offset)
     
    static int
    decodeUnsignedShort(byte[] a, int offset)
     
    static int
    decodeUnsignedShortLE(byte[] a, int offset)
    Decode unsigned short
    static byte[]
    encodeInt(int x)
     
    static byte[]
    encodeInt(int x, byte[] a, int offset)
    write an int into a byte array at offset and returns the array
    static byte[]
    encodeLong(long x)
    write a long in to a byte array of 8 bytes
    static byte[]
    encodeLong(long x, byte[] a, int offset)
    write an long into a byte array at offset and returns the array
    static byte[]
    encodeLongLE(long x, byte[] a, int offset)
     
    static byte[]
    encodeUnsigned3Bytes(int x, byte[] a, int offset)
     
    static byte[]
    encodeUnsigned5Bytes(long x, byte[] a, int offset)
     
    static byte[]
    encodeUnsigned6Bytes(long x, byte[] a, int offset)
     
    static byte[]
    encodeUnsignedShort(int x, byte[] a, int offset)
     
    static byte[]
    minusOne(byte[] a)
     
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 in to a byte array of 8 bytes
      Parameters:
      x -
      Returns:
    • 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
    • encodeInt

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

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

      public static int decodeIntLE(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)
    • decodeShort

      public static short decodeShort(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: