public class Hex extends java.lang.Object implements BinaryEncoder, BinaryDecoder
DEFAULT_CHARSET_NAME
This class is thread-safe.Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
DEFAULT_CHARSET
Default charset is
StandardCharsets.UTF_8 |
static java.lang.String |
DEFAULT_CHARSET_NAME
Default charset name is
CharEncoding.UTF_8 |
Constructor and Description |
---|
Hex()
Creates a new codec with the default charset name
DEFAULT_CHARSET |
Hex(java.nio.charset.Charset charset)
Creates a new codec with the given Charset.
|
Hex(java.lang.String charsetName)
Creates a new codec with the given charset name.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
decode(byte[] array)
Converts an array of character bytes representing hexadecimal values into an array of bytes of those same values.
|
byte[] |
decode(java.nio.ByteBuffer buffer)
Converts a buffer of character bytes representing hexadecimal values into an array of bytes of those same values.
|
java.lang.Object |
decode(java.lang.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[] |
decodeHex(java.lang.String data)
Converts a String representing hexadecimal values into an array of bytes of those same values.
|
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.
|
byte[] |
encode(java.nio.ByteBuffer array)
Converts byte buffer into an array of bytes for the characters representing the hexadecimal values of each byte
in order.
|
java.lang.Object |
encode(java.lang.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.
|
static char[] |
encodeHex(java.nio.ByteBuffer data)
Converts a byte buffer into an array of characters representing the hexadecimal values of each byte in order.
|
static char[] |
encodeHex(java.nio.ByteBuffer data,
boolean toLowerCase)
Converts a byte buffer into an array of characters representing the hexadecimal values of each byte in order.
|
static java.lang.String |
encodeHexString(byte[] data)
Converts an array of bytes into a String representing the hexadecimal values of each byte in order.
|
static java.lang.String |
encodeHexString(byte[] data,
boolean toLowerCase)
Converts an array of bytes into a String representing the hexadecimal values of each byte in order.
|
static java.lang.String |
encodeHexString(java.nio.ByteBuffer data)
Converts a byte buffer into a String representing the hexadecimal values of each byte in order.
|
static java.lang.String |
encodeHexString(java.nio.ByteBuffer data,
boolean toLowerCase)
Converts a byte buffer into a String representing the hexadecimal values of each byte in order.
|
java.nio.charset.Charset |
getCharset()
Gets the charset.
|
java.lang.String |
getCharsetName()
Gets the charset name.
|
java.lang.String |
toString()
Returns a string representation of the object, which includes the charset name.
|
public static final java.nio.charset.Charset DEFAULT_CHARSET
StandardCharsets.UTF_8
public static final java.lang.String DEFAULT_CHARSET_NAME
CharEncoding.UTF_8
public Hex()
DEFAULT_CHARSET
public Hex(java.nio.charset.Charset charset)
charset
- the charset.public Hex(java.lang.String charsetName)
charsetName
- the charset name.java.nio.charset.UnsupportedCharsetException
- If the named charset is unavailablepublic static byte[] decodeHex(java.lang.String data) throws DecoderException
data
- A String containing hexadecimal digitsDecoderException
- Thrown if an odd number or illegal of characters is suppliedpublic static byte[] decodeHex(char[] data) throws DecoderException
data
- An array of characters containing hexadecimal digitsDecoderException
- 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(java.nio.ByteBuffer data)
All bytes identified by Buffer.remaining()
will be used; after this method
the value remaining()
will be zero.
data
- a byte buffer 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 uppercasepublic static char[] encodeHex(java.nio.ByteBuffer data, boolean toLowerCase)
All bytes identified by Buffer.remaining()
will be used; after this method
the value remaining()
will be zero.
data
- a byte buffer to convert to Hex characterstoLowerCase
- true
converts to lowercase, false
to uppercasepublic static java.lang.String encodeHexString(byte[] data)
data
- a byte[] to convert to Hex characterspublic static java.lang.String encodeHexString(byte[] data, boolean toLowerCase)
data
- a byte[] to convert to Hex characterstoLowerCase
- true
converts to lowercase, false
to uppercasepublic static java.lang.String encodeHexString(java.nio.ByteBuffer data)
All bytes identified by Buffer.remaining()
will be used; after this method
the value remaining()
will be zero.
data
- a byte buffer to convert to Hex characterspublic static java.lang.String encodeHexString(java.nio.ByteBuffer data, boolean toLowerCase)
All bytes identified by Buffer.remaining()
will be used; after this method
the value remaining()
will be zero.
data
- a byte buffer to convert to Hex characterstoLowerCase
- true
converts to lowercase, false
to uppercasepublic byte[] decode(byte[] array) throws DecoderException
decode
in interface BinaryDecoder
array
- An array of character bytes containing hexadecimal digitsDecoderException
- Thrown if an odd number of characters is supplied to this functiondecodeHex(char[])
public byte[] decode(java.nio.ByteBuffer buffer) throws DecoderException
All bytes identified by Buffer.remaining()
will be used; after this method
the value remaining()
will be zero.
buffer
- An array of character bytes containing hexadecimal digitsDecoderException
- Thrown if an odd number of characters is supplied to this functiondecodeHex(char[])
public java.lang.Object decode(java.lang.Object object) throws DecoderException
decode
in interface Decoder
object
- A String, ByteBuffer, byte[], or an array of character bytes containing hexadecimal digitsDecoderException
- Thrown if an odd number of characters is supplied to this function or the object is not
a String or char[]decodeHex(char[])
public byte[] encode(byte[] array)
The conversion from hexadecimal characters to the returned bytes is performed with the charset named by
getCharset()
.
encode
in interface BinaryEncoder
array
- a byte[] to convert to Hex charactersencodeHex(byte[])
public byte[] encode(java.nio.ByteBuffer array)
The conversion from hexadecimal characters to the returned bytes is performed with the charset named by
getCharset()
.
All bytes identified by Buffer.remaining()
will be used; after this method
the value remaining()
will be zero.
array
- a byte buffer to convert to Hex charactersencodeHex(byte[])
public java.lang.Object encode(java.lang.Object object) throws EncoderException
The conversion from hexadecimal characters to bytes to be encoded to performed with the charset named by
getCharset()
.
encode
in interface Encoder
object
- a String, ByteBuffer, or byte[] to convert to Hex charactersEncoderException
- Thrown if the given object is not a String or byte[]encodeHex(byte[])
public java.nio.charset.Charset getCharset()
public java.lang.String getCharsetName()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2010 - 2020 Adobe. All Rights Reserved