Package org.ldaptive.io
Class Hex
java.lang.Object
org.ldaptive.io.Hex
Utility for hexadecimal encoding and decoding.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decode(char... value) This will convert the supplied value from a hex encoded string.private static intdecode(char[] hex, int i) Decodes the supplied character to its corresponding nibble.static char[]encode(byte... value) This will convert the supplied value to a hex encoded string.static booleanisValidChar(char c) Returns whether the supplied character is a hexadecimal character.
-
Field Details
-
HEX_CHARS
private static final char[] HEX_CHARSHexadecimal characters. -
DECODE
private static final byte[] DECODEDecode table which stores characters from 0 to f. Anything higher than 'f' is invalid so that is the max size of the array.
-
-
Constructor Details
-
Hex
private Hex()Default constructor.
-
-
Method Details
-
isValidChar
public static boolean isValidChar(char c) Returns whether the supplied character is a hexadecimal character. Valid characters include 0-9, a-f and A-F- Parameters:
c- to inspect- Returns:
- whether the supplied character is hexadecimal
-
encode
public static char[] encode(byte... value) This will convert the supplied value to a hex encoded string. Returns null if the supplied value is null.- Parameters:
value- to hex encode- Returns:
- hex encoded value
-
decode
public static byte[] decode(char... value) This will convert the supplied value from a hex encoded string. Returns null if the supplied value is null.- Parameters:
value- to hex decode- Returns:
- hex decoded value
- Throws:
IllegalArgumentException- if value is not valid hexadecimal
-
decode
private static int decode(char[] hex, int i) Decodes the supplied character to its corresponding nibble.- Parameters:
hex- to read character fromi- index of hex to read- Returns:
- 0-15 integer
- Throws:
IllegalArgumentException- if the character is not valid hex
-