Package org.apache.tomcat.util.buf
Class HexUtils
- java.lang.Object
-
- org.apache.tomcat.util.buf.HexUtils
-
public final class HexUtils extends java.lang.ObjectTables useful when converting byte arrays to and from strings of hexadecimal digits. Code from Ajp11, from Apache's JServ.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]fromHexString(java.lang.String input)Convert a hexadecimal string to a byte array.static intgetDec(int index)Get the decimal value of the character at the given index.static bytegetHex(int index)Get the hexadecimal byte for the given index.static java.lang.StringtoHexString(byte[] bytes)Convert a byte array to a hexadecimal string representation.static java.lang.StringtoHexString(char c)Convert a character to a hexadecimal string representation.
-
-
-
Method Detail
-
getDec
public static int getDec(int index)
Get the decimal value of the character at the given index.- Parameters:
index- the character index- Returns:
- the decimal value, or -1 if the character is not a valid hex digit
-
getHex
public static byte getHex(int index)
Get the hexadecimal byte for the given index.- Parameters:
index- the index into the hex table- Returns:
- the hexadecimal byte
-
toHexString
public static java.lang.String toHexString(char c)
Convert a character to a hexadecimal string representation.- Parameters:
c- the character to convert- Returns:
- the hexadecimal string representation of the character
-
toHexString
public static java.lang.String toHexString(byte[] bytes)
Convert a byte array to a hexadecimal string representation.- Parameters:
bytes- the byte array to convert- Returns:
- the hexadecimal string, or
nullif the input isnull
-
fromHexString
public static byte[] fromHexString(java.lang.String input)
Convert a hexadecimal string to a byte array.- Parameters:
input- the hexadecimal string to convert- Returns:
- the byte array, or
nullif the input isnull - Throws:
java.lang.IllegalArgumentException- if the input has an odd number of characters or contains non-hexadecimal characters
-
-