Class HexUtils
java.lang.Object
org.apache.tomcat.util.buf.HexUtils
Tables useful when converting byte arrays to and from strings of hexadecimal digits. Code from Ajp11, from Apache's
JServ.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]fromHexString(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 StringtoHexString(byte[] bytes) Convert a byte array to a hexadecimal string representation.static StringtoHexString(char c) Convert a character to a hexadecimal string representation.
-
Method Details
-
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
Convert a character to a hexadecimal string representation.- Parameters:
c- the character to convert- Returns:
- the hexadecimal string representation of the character
-
toHexString
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
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:
IllegalArgumentException- if the input has an odd number of characters or contains non-hexadecimal characters
-