Class ByteUtil


  • public final class ByteUtil
    extends Object
    Class that contains many static methods for byte handling.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] array​(int length, byte value)
      Get a new array with a specific length and filled with a byte value.
      static byte[] concat​(byte[] bytes1, byte[] bytes2)
      Concatenates two byte arrays.
      static byte[] copy​(byte[] bytes)
      Copy an entire array.
      static byte[] copy​(byte[] bytes, int start, int end)
      Copy part of an array.
      static boolean equalArrays​(byte[] bytes1, byte[] bytes2)
      Check if two arrays of bytes are equal.
      static byte[] toBytes​(char[] hexadecimal)
      Get an array of bytes from a given hexadecimal char array.
      static byte[] toBytes​(long number)
      Get an array of bytes from a given number.
      static byte[] toBytes​(long... numbers)
      Get an array of bytes from a given array of numbers.
      static byte[] toBytes​(String hexadecimal)
      Get an array of bytes from a given hexadecimal string.
      static String toHexadecimal​(byte[] bytes)
      Get a hexadecimal string from given array of bytes.
      static String toHexadecimal​(long number)
      Get a hexadecimal string from given number.
      static String toHexadecimal​(long... numbers)
      Get a hexadecimal string from given number.
      static char[] toHexadecimalChars​(byte[] bytes)
      Get a hexadecimal char array from given array of bytes.
      static char[] toHexadecimalChars​(long... numbers)
      Get a hexadecimal char array from given array of numbers.
      static long toNumber​(byte[] bytes)
      Get a number from a given array of bytes.
      static long toNumber​(byte[] bytes, int start, int length)
      Get a number from a given array of bytes.
      static long toNumber​(char[] hexadecimal)
      Get a number from a given hexadecimal char array.
      static long toNumber​(String hexadecimal)
      Get a number from a given hexadecimal string.
    • Method Detail

      • toNumber

        public static long toNumber​(String hexadecimal)
        Get a number from a given hexadecimal string.
        Parameters:
        hexadecimal - a string
        Returns:
        a long
      • toNumber

        public static long toNumber​(char[] hexadecimal)
        Get a number from a given hexadecimal char array.
        Parameters:
        hexadecimal - a string
        Returns:
        a long
      • toNumber

        public static long toNumber​(byte[] bytes)
        Get a number from a given array of bytes.
        Parameters:
        bytes - a byte array
        Returns:
        a long
      • toNumber

        public static long toNumber​(byte[] bytes,
                                    int start,
                                    int length)
        Get a number from a given array of bytes.
        Parameters:
        bytes - a byte array
        start - first byte of the number
        length - byte length of the number
        Returns:
        a long
      • toBytes

        public static byte[] toBytes​(long number)
        Get an array of bytes from a given number.
        Parameters:
        number - a number
        Returns:
        a byte array
      • toBytes

        public static byte[] toBytes​(long... numbers)
        Get an array of bytes from a given array of numbers.
        Parameters:
        numbers - an array of numbers
        Returns:
        a byte array
      • toBytes

        public static byte[] toBytes​(String hexadecimal)
        Get an array of bytes from a given hexadecimal string.
        Parameters:
        hexadecimal - a string
        Returns:
        a byte array
      • toBytes

        public static byte[] toBytes​(char[] hexadecimal)
        Get an array of bytes from a given hexadecimal char array.
        Parameters:
        hexadecimal - a string
        Returns:
        a byte array
      • toHexadecimal

        public static String toHexadecimal​(byte[] bytes)
        Get a hexadecimal string from given array of bytes.
        Parameters:
        bytes - byte array
        Returns:
        a string
      • toHexadecimalChars

        public static char[] toHexadecimalChars​(byte[] bytes)
        Get a hexadecimal char array from given array of bytes.
        Parameters:
        bytes - byte array
        Returns:
        a char array
      • toHexadecimalChars

        public static char[] toHexadecimalChars​(long... numbers)
        Get a hexadecimal char array from given array of numbers.
        Parameters:
        numbers - an array of numbers
        Returns:
        a char array
      • toHexadecimal

        public static String toHexadecimal​(long... numbers)
        Get a hexadecimal string from given number.
        Parameters:
        numbers - an array of numbers
        Returns:
        a string
      • toHexadecimal

        public static String toHexadecimal​(long number)
        Get a hexadecimal string from given number.
        Parameters:
        number - a number
        Returns:
        a string
      • array

        public static byte[] array​(int length,
                                   byte value)
        Get a new array with a specific length and filled with a byte value.
        Parameters:
        length - array size
        value - byte value
        Returns:
        a byte array
      • copy

        public static byte[] copy​(byte[] bytes)
        Copy an entire array.
        Parameters:
        bytes - byte array
        Returns:
        a byte array
      • copy

        public static byte[] copy​(byte[] bytes,
                                  int start,
                                  int end)
        Copy part of an array.
        Parameters:
        bytes - byte array
        start - start position
        end - end position
        Returns:
        a byte array
      • concat

        public static byte[] concat​(byte[] bytes1,
                                    byte[] bytes2)
        Concatenates two byte arrays.
        Parameters:
        bytes1 - byte array 1
        bytes2 - byte array 2
        Returns:
        a byte array
      • equalArrays

        public static boolean equalArrays​(byte[] bytes1,
                                          byte[] bytes2)
        Check if two arrays of bytes are equal.
        Parameters:
        bytes1 - byte array 1
        bytes2 - byte array 2
        Returns:
        a boolean