Class ByteUtil


  • public final class ByteUtil
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String bytesToHexstring​(byte[] bytes, String delimiter)
      Converts bytes to a hex string.
      static long bytesToUnsignedInt​(byte[] bytes)
      Converts a 4 byte array of unsigned bytes to unsigned int.
      static long bytesToUnsignedMedium​(byte[] bytes)
      Converts a 3 byte array of unsigned bytes to unsigned int.
      static int bytesToUnsignedShort​(byte[] bytes)
      Converts a 2 byte array of unsigned bytes to unsigned short.
      static @org.eclipse.jdt.annotation.Nullable byte[] convertBigIntegerToNBytes​(@Nullable BigInteger bigInteger, int numBytes)
      Utility method to convert BigInteger to n element byte array.
      static @org.eclipse.jdt.annotation.Nullable byte[] uint64toBytes​(@Nullable org.opendaylight.yangtools.yang.common.Uint64 uint)
      Utility method to convert an Uint64 to an 8-byte array.
      static byte[] unsignedIntToBytes​(Long unsignedInt)
      Converts unsigned integer to a 4 byte array of unsigned bytes.
      static byte[] unsignedIntToBytes​(org.opendaylight.yangtools.yang.common.Uint32 unsignedInt)
      Converts unsigned integer to a 4 byte array of unsigned bytes.
      static byte[] unsignedMediumToBytes​(Long unsignedInt)
      Converts unsigned integer to a 3 byte array of unsigned bytes.
      static byte[] unsignedMediumToBytes​(org.opendaylight.yangtools.yang.common.Uint32 unsignedInt)
      Converts unsigned integer to a 3 byte array of unsigned bytes.
      static byte[] unsignedShortToBytes​(Integer unsignedShort)
      Converts unsigned short to a 2 byte array of unsigned bytes.
      static byte[] unsignedShortToBytes​(org.opendaylight.yangtools.yang.common.Uint16 unsignedShort)
      Converts unsigned short to a 2 byte array of unsigned bytes.
    • Method Detail

      • bytesToHexstring

        public static String bytesToHexstring​(byte[] bytes,
                                              String delimiter)
        Converts bytes to a hex string.
        Parameters:
        bytes - bytes that needs to be converted to hex
        delimiter - string delimiter
        Returns:
        hexString containing bytes, separated with delimiter
      • convertBigIntegerToNBytes

        public static @org.eclipse.jdt.annotation.Nullable byte[] convertBigIntegerToNBytes​(@Nullable BigInteger bigInteger,
                                                                                            int numBytes)
        Utility method to convert BigInteger to n element byte array.
        Parameters:
        bigInteger - big integer value that needs to be converted to byte
        numBytes - convert to number of bytes
        Returns:
        byte array containing n * 8 bits.
      • uint64toBytes

        public static @org.eclipse.jdt.annotation.Nullable byte[] uint64toBytes​(@Nullable org.opendaylight.yangtools.yang.common.Uint64 uint)
        Utility method to convert an Uint64 to an 8-byte array.
        Parameters:
        uint - Unsigned long, potentially null.
        Returns:
        byte array, or null if input was null.
      • bytesToUnsignedInt

        public static long bytesToUnsignedInt​(byte[] bytes)
        Converts a 4 byte array of unsigned bytes to unsigned int.
        Parameters:
        bytes - an array of 4 unsigned bytes
        Returns:
        a long representing the unsigned int
      • bytesToUnsignedMedium

        public static long bytesToUnsignedMedium​(byte[] bytes)
        Converts a 3 byte array of unsigned bytes to unsigned int.
        Parameters:
        bytes - an array of 4 unsigned bytes
        Returns:
        a long representing the unsigned int
      • bytesToUnsignedShort

        public static int bytesToUnsignedShort​(byte[] bytes)
        Converts a 2 byte array of unsigned bytes to unsigned short.
        Parameters:
        bytes - an array of 2 unsigned bytes
        Returns:
        an int representing the unsigned short
      • unsignedIntToBytes

        public static byte[] unsignedIntToBytes​(Long unsignedInt)
        Converts unsigned integer to a 4 byte array of unsigned bytes.
        Parameters:
        unsignedInt - representing the unsigned integer
        Returns:
        bytes an array of 4 unsigned bytes
      • unsignedIntToBytes

        public static byte[] unsignedIntToBytes​(org.opendaylight.yangtools.yang.common.Uint32 unsignedInt)
        Converts unsigned integer to a 4 byte array of unsigned bytes.
        Parameters:
        unsignedInt - representing the unsigned integer
        Returns:
        bytes an array of 4 unsigned bytes
      • unsignedMediumToBytes

        public static byte[] unsignedMediumToBytes​(Long unsignedInt)
        Converts unsigned integer to a 3 byte array of unsigned bytes.
        Parameters:
        unsignedInt - representing the unsigned integer
        Returns:
        bytes an array of 3 unsigned bytes
      • unsignedMediumToBytes

        public static byte[] unsignedMediumToBytes​(org.opendaylight.yangtools.yang.common.Uint32 unsignedInt)
        Converts unsigned integer to a 3 byte array of unsigned bytes.
        Parameters:
        unsignedInt - representing the unsigned integer
        Returns:
        bytes an array of 3 unsigned bytes
      • unsignedShortToBytes

        public static byte[] unsignedShortToBytes​(Integer unsignedShort)
        Converts unsigned short to a 2 byte array of unsigned bytes.
        Parameters:
        unsignedShort - representing the unsigned short
        Returns:
        bytes an array of 2 unsigned bytes
      • unsignedShortToBytes

        public static byte[] unsignedShortToBytes​(org.opendaylight.yangtools.yang.common.Uint16 unsignedShort)
        Converts unsigned short to a 2 byte array of unsigned bytes.
        Parameters:
        unsignedShort - representing the unsigned short
        Returns:
        bytes an array of 2 unsigned bytes