Package com.landawn.abacus.util
Class Hex
- java.lang.Object
-
- com.landawn.abacus.util.Hex
-
public class Hex extends Object
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#DEFAULT_CHARSET_NAME
This class is thread-safe.- Since:
- 1.1
- Version:
- $Id: Hex.java 1619948 2014-08-22 22:53:55Z ggregory $
-
-
Constructor Summary
Constructors Constructor Description Hex()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
decode(char[] data)
Converts an array of characters representing hexadecimal values into an array of bytes of those same values.static byte[]
decode(String data)
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 Detail
-
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
public static String encodeToString(byte[] data)
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
public static String encodeToString(byte[] data, boolean toLowerCase)
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
public static byte[] decode(String data) throws IllegalArgumentException
- Parameters:
data
-- Returns:
- Throws:
IllegalArgumentException
- the illegal argument exception
-
decode
public static byte[] decode(char[] data) throws IllegalArgumentException
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
-
-