java.lang.Object
org.seppiko.commons.utils.codec.HexUtil
Hex (Base16) Encoder / Decoder Util.
- Author:
- Leonard Woo
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char[]Hexadecimal character array with lower lettersstatic final intHexadecimal lengthstatic final char[]Hexadecimal character array with upper letters -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decode(char[] data) convert hex char array to byte arraystatic byte[]convert hex string with split to byte arraystatic byte[]decodeString(String data) convert hex string with whitespace split to byte arraystatic char[]encode(byte[] data) convert byte array to hex char arraystatic char[]encode(byte[] data, boolean toLowerCase) convert byte array to hex char arraystatic StringencodeString(byte[] data) convert byte array to string objectstatic StringencodeString(byte[] data, String split) convert byte array to string objectstatic char[]encodeWithBytes(byte[] data) convert byte array to hex char arraystatic inthexDigit(char ch) Returns the numeric value of the hexadecimal characterch
-
Field Details
-
HEXADECIMAL_LENGTH
public static final int HEXADECIMAL_LENGTHHexadecimal length- See Also:
-
HEXADECIMAL
public static final char[] HEXADECIMALHexadecimal character array with lower letters -
HEXADECIMAL_UPPER
public static final char[] HEXADECIMAL_UPPERHexadecimal character array with upper letters
-
-
Method Details
-
hexDigit
public static int hexDigit(char ch) Returns the numeric value of the hexadecimal characterch- Parameters:
ch- the character to be converted- Returns:
- the numeric value represented by the hexadecimal character
- See Also:
-
encodeWithBytes
public static char[] encodeWithBytes(byte[] data) convert byte array to hex char array- Parameters:
data- byte array data- Returns:
- hex char array
-
encodeString
convert byte array to string object- Parameters:
data- byte array data- Returns:
- string object
-
encodeString
convert byte array to string object- Parameters:
data- byte array datasplit- string object split- Returns:
- string object
-
encode
public static char[] encode(byte[] data) convert byte array to hex char array- Parameters:
data- byte array data- Returns:
- hex char array
-
encode
public static char[] encode(byte[] data, boolean toLowerCase) convert byte array to hex char array- Parameters:
data- byte array datatoLowerCase- true is lower case, false is upper case- Returns:
- hex char array
-
decodeString
convert hex string with whitespace split to byte array- Parameters:
data- hex string- Returns:
- byte array
- Throws:
IllegalArgumentException- data include invalid characterNullPointerException- when data or separator is null
-
decode
public static byte[] decode(String data, String split) throws IllegalArgumentException, NullPointerException convert hex string with split to byte array- Parameters:
data- hex stringsplit- split- Returns:
- byte array
- Throws:
IllegalArgumentException- data include invalid characterNullPointerException- when data or separator is null
-
decode
convert hex char array to byte array- Parameters:
data- hex char array- Returns:
- byte array
- Throws:
IllegalArgumentException- data include invalid characterNullPointerException- data is null or empty
-