Class Hex

java.lang.Object
org.apache.directory.api.util.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 Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Convert an escaoed list of bytes to a byte[]
    static String
    Decodes values of attributes in the DN encoded in hex into a UTF-8 String.
    static char[]
    encodeHex(byte[] data)
    Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.
    static byte
    getHexValue(byte high, byte low)
    Translate two bytes to an hex value.
    static byte
    getHexValue(char c)
    Return an hex value from a single char The char must be in [0-9a-fA-F]
    static byte
    getHexValue(char high, char low)
    Translate two chars to an hex value.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • 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
    • convertEscapedHex

      public static byte[] convertEscapedHex(String str) throws InvalidNameException
      Convert an escaoed list of bytes to a byte[]
      Parameters:
      str - the string containing hex escapes
      Returns:
      the converted byte[]
      Throws:
      InvalidNameException - If we can't convert the String to a byte[]
    • 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