org.apache.directory.shared.util
Class Hex

java.lang.Object
  extended by org.apache.directory.shared.util.Hex

public 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

Field Summary
static char[] HEX_CHAR
          Used to build output as Hex
static byte[] HEX_VALUE
          <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66]
 
Constructor Summary
Hex()
           
 
Method Summary
static byte[] convertEscapedHex(String str)
          Convert an escaoed list of bytes to a byte[]
static String decodeHexString(String str)
          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 hexidecimal 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 sinle 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEX_VALUE

public static final byte[] HEX_VALUE
<hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66]


HEX_CHAR

public static final char[] HEX_CHAR
Used to build output as Hex

Constructor Detail

Hex

public Hex()
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 sinle 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

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

encodeHex

public static char[] encodeHex(byte[] data)
Converts an array of bytes into an array of characters representing the hexidecimal 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 hexidecimal characters


Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.