public class Hex extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_CHARSET_NAME
Default charset name is UTF_8
|
| 构造器和说明 |
|---|
Hex()
Creates a new codec with the default charset name
DEFAULT_CHARSET_NAME |
Hex(String csName)
Creates a new codec with the given charset name.
|
| 限定符和类型 | 方法和说明 |
|---|---|
byte[] |
decode(byte[] array)
Converts an array of character bytes representing hexadecimal values into
an array of bytes of those same values.
|
Object |
decode(Object object)
Converts a String or an array of character bytes representing hexadecimal
values into an array of bytes of those same values.
|
static byte[] |
decodeHex(char[] data)
Converts an array of characters representing hexadecimal values into an
array of bytes of those same values.
|
static byte[] |
encode(byte[] array)
Converts an array of bytes into an array of bytes for the characters
representing the hexadecimal values of each byte in order.
|
Object |
encode(Object object)
Converts a String or an array of bytes into an array of characters
representing the hexadecimal values of each byte in order.
|
static char[] |
encodeHex(byte[] data)
Converts an array of bytes into an array of characters representing the
hexadecimal values of each byte in order.
|
static char[] |
encodeHex(byte[] data,
boolean toLowerCase)
Converts an array of bytes into an array of characters representing the
hexadecimal values of each byte in order.
|
protected static char[] |
encodeHex(byte[] data,
char[] toDigits)
Converts an array of bytes into an array of characters representing the
hexadecimal values of each byte in order.
|
static String |
encodeHexString(byte[] data)
Converts an array of bytes into a String representing the hexadecimal
values of each byte in order.
|
String |
getCharsetName()
Gets the charset name.
|
protected static int |
toDigit(char ch,
int index)
Converts a hexadecimal character to an integer.
|
String |
toString()
Returns a string representation of the object, which includes the charset
name.
|
public Hex()
DEFAULT_CHARSET_NAMEpublic Hex(String csName)
csName - the charset name.public static byte[] decodeHex(char[] data)
throws Exception
data - An array of characters containing hexadecimal digitsException - Thrown if an odd number or illegal of characters is
suppliedpublic static char[] encodeHex(byte[] data)
data - a byte[] to convert to Hex characterspublic static char[] encodeHex(byte[] data,
boolean toLowerCase)
data - a byte[] to convert to Hex characterstoLowerCase - true converts to lowercase,
false to uppercaseprotected static char[] encodeHex(byte[] data,
char[] toDigits)
data - a byte[] to convert to Hex characterstoDigits - the output alphabetpublic static String encodeHexString(byte[] data)
data - a byte[] to convert to Hex charactersprotected static int toDigit(char ch,
int index)
throws Exception
ch - A character to convert to an integer digitindex - The index of the character in the sourceException - Thrown if ch is an illegal hex characterpublic byte[] decode(byte[] array)
throws Exception
array - An array of character bytes containing hexadecimal digitsException - Thrown if an odd number of characters is supplied to
this functiondecodeHex(char[])public Object decode(Object object) throws Exception
object - A String or, an array of character bytes containing
hexadecimal digitsException - Thrown if an odd number of characters is supplied to
this function or the object is not a String or char[]decodeHex(char[])public static byte[] encode(byte[] array)
throws UnsupportedEncodingException
The conversion from hexadecimal characters to the returned bytes is
performed with the charset named by getCharsetName().
array - a byte[] to convert to Hex charactersIllegalStateException - if the charsetName is invalid. This API
throws IllegalStateException instead of
Exception for backward compatibility.UnsupportedEncodingExceptionencodeHex(byte[])public Object encode(Object object) throws Exception
The conversion from hexadecimal characters to bytes to be encoded to
performed with the charset named by getCharsetName().
object - a String, or byte[] to convert to Hex charactersException - Thrown if the given object is not a String or byte[]encodeHex(byte[])public String getCharsetName()
Copyright © 2017. All rights reserved.