Package com.landawn.abacus.util
Class Hex
java.lang.Object
com.landawn.abacus.util.Hex
Note: copied from Apache commons-codec: https://commons.apache.org/proper/commons-codec.
Converts hexadecimal Strings. The charset used for certain operation can be set, the default is set in
This class is thread-safe.
invalid @link
#DEFAULT_CHARSET_NAME
- Since:
- 1.1
- Version:
- $Id: Hex.java 1619948 2014-08-22 22:53:55Z ggregory $
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decode
(char[] data) Converts an array of characters representing hexadecimal values into an array of bytes of those same values.static byte[]
static char[]
encode
(byte[] data) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.static char[]
encode
(byte[] data, boolean toLowerCase) Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.static String
encodeToString
(byte[] data) Converts an array of bytes into a String representing the hexadecimal values of each byte in order.static String
encodeToString
(byte[] data, boolean toLowerCase) Converts an array of bytes into a String representing the hexadecimal values of each byte in order.
-
Method Details
-
encode
public static char[] encode(byte[] data) Converts an array of bytes into an array of characters representing the hexadecimal 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 hexadecimal characters
-
encode
public static char[] encode(byte[] data, boolean toLowerCase) Converts an array of bytes into an array of characters representing the hexadecimal 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 characterstoLowerCase
-true
converts to lowercase,false
to uppercase- Returns:
- A char[] containing hexadecimal characters
- Since:
- 1.4
-
encodeToString
Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned String 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 String containing hexadecimal characters
- Since:
- 1.4
-
encodeToString
Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned String 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 characterstoLowerCase
-true
converts to lowercase,false
to uppercase- Returns:
- A String containing hexadecimal characters
- Since:
- 1.4
-
decode
- Parameters:
data
-- Returns:
- Throws:
IllegalArgumentException
- the illegal argument exception
-
decode
Converts an array of characters representing hexadecimal values into an array of bytes of those same values. The returned array will be half the length of the passed array, as it takes two characters to represent any given byte. An exception is thrown if the passed char array has an odd number of elements.- Parameters:
data
- An array of characters containing hexadecimal digits- Returns:
- A byte array containing binary data decoded from the supplied char array.
- Throws:
IllegalArgumentException
- the illegal argument exception
-