Class Hex


  • public final class Hex
    extends Object
    Various hex and string manipulation methods that are more efficient then chaining operations: all is done in the same buffer without creating a bunch of intermediate String objects.
    Author:
    Apache Directory Project
    • Method Detail

      • getHexValue

        public static byte getHexValue​(char high,
                                       char low)
        Translate two chars to an hex value. The chars must be in [a-fA-F0-9]
        Parameters:
        high - The high value
        low - The low value
        Returns:
        A byte representation of the two chars
      • getHexValue

        public static byte getHexValue​(byte high,
                                       byte low)
        Translate two bytes to an hex value. The bytes must be in [0-9a-fA-F]
        Parameters:
        high - The high value
        low - The low value
        Returns:
        A byte representation of the two bytes
      • getHexValue

        public static byte getHexValue​(char c)
        Return an hex value from a single char The char must be in [0-9a-fA-F]
        Parameters:
        c - The char we want to convert
        Returns:
        A byte between 0 and 15
      • decodeHexString

        public static String decodeHexString​(String str)
                                      throws InvalidNameException
        Decodes values of attributes in the DN encoded in hex into a UTF-8 String. RFC2253 allows a DN's attribute to be encoded in hex. The encoded value starts with a # then is followed by an even number of hex characters.
        Parameters:
        str - the string to decode
        Returns:
        the decoded string
        Throws:
        InvalidNameException - If we can't decode the String to an UTF-8 String
      • encodeHex

        public static char[] encodeHex​(byte[] data)
        Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.
        Parameters:
        data - a byte[] to convert to Hex characters
        Returns:
        A char[] containing hexadecimal characters