Class HexString


  • public final class HexString
    extends Object
    • Method Detail

      • toHexString

        public static String toHexString​(byte[] bytes)
        Convert a byte array to a colon-separated hex string.
        Parameters:
        bytes - byte array to be converted
        Returns:
        converted colon-separated hex string, e.g. "0f:ca:fe:de:ad:be:ef", or "(null)" if given byte array is null
      • toHexString

        public static String toHexString​(byte[] bytes,
                                         String separator)
        Convert a byte array to a hex string separated by given separator.
        Parameters:
        bytes - byte array to be converted
        separator - the string use to separate each byte
        Returns:
        converted hex string, or "(null)" if given byte array is null
      • toHexString

        public static String toHexString​(long val,
                                         int padTo)
        Convert a long number to colon-separated hex string. Prepend zero padding until given length.
        Parameters:
        val - long number to be converted
        padTo - prepend zeros until this length
        Returns:
        converted colon-separated hex string, e.g. "0f:ca:fe:de:ad:be:ef"
      • toHexString

        public static String toHexString​(long val)
        Convert a long number to colon-separated hex string. Prepend zero padding until 8 bytes.
        Parameters:
        val - long number to be converted
        Returns:
        converted colon-separated hex string, e.g. "0f:ca:fe:de:ad:be:ef"
      • fromHexString

        public static byte[] fromHexString​(String values)
        Convert a colon-separated hex string to byte array.
        Parameters:
        values - colon-separated hex string to be converted, e.g. "0f:ca:fe:de:ad:be:ef"
        Returns:
        converted byte array
        Throws:
        NumberFormatException - if input hex string cannot be parsed
      • fromHexString

        public static byte[] fromHexString​(String values,
                                           String separator)
        Convert a hex-string with arbitrary separator to byte array. If separator is the empty string or null, then no separator will be considered.
        Parameters:
        values - hex string to be converted
        separator - regex for separator
        Returns:
        converted byte array
        Throws:
        NumberFormatException - if input hex string cannot be parsed
      • toLong

        public static long toLong​(String value)
        Convert a colon-separated hex string to long.
        Parameters:
        value - colon-separated hex string to be converted, e.g. "00:0f:ca:fe:de:ad:be:ef"
        Returns:
        converted long number
        Throws:
        NumberFormatException - if input hex string cannot be parsed