Package org.cryptacular.codec
Class HexEncoder
java.lang.Object
org.cryptacular.codec.HexEncoder
- All Implemented Interfaces:
Encoder
Stateless hexadecimal byte-to-character encoder.
- Author:
- Middleware Services
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance that does not delimit bytes in the output hex string.HexEncoder
(boolean delimitBytes) Creates a new instance with optional colon-delimiting of bytes.HexEncoder
(boolean delimitBytes, boolean uppercase) Creates a new instance with optional colon-delimiting of bytes and uppercase output. -
Method Summary
Modifier and TypeMethodDescriptionvoid
encode
(ByteBuffer input, CharBuffer output) Encodes bytes in input buffer into characters placed in the output buffer.void
finalize
(CharBuffer output) Performs final output encoding (e.g.int
outputSize
(int inputSize) Expected number of characters in the output buffer for an input buffer of the given size.
-
Constructor Details
-
HexEncoder
public HexEncoder()Creates a new instance that does not delimit bytes in the output hex string. -
HexEncoder
public HexEncoder(boolean delimitBytes) Creates a new instance with optional colon-delimiting of bytes.- Parameters:
delimitBytes
- True to delimit every two characters (i.e. every byte) with ':' character.
-
HexEncoder
public HexEncoder(boolean delimitBytes, boolean uppercase) Creates a new instance with optional colon-delimiting of bytes and uppercase output.- Parameters:
delimitBytes
- True to delimit every two characters (i.e. every byte) with ':' character.uppercase
- True to output uppercase alphabetic characters, false for lowercase.
-
-
Method Details
-
encode
Description copied from interface:Encoder
Encodes bytes in input buffer into characters placed in the output buffer. This method may be called multiple times, followed byEncoder.finalize(java.nio.CharBuffer)
after all input bytes have been provided.- Specified by:
encode
in interfaceEncoder
- Parameters:
input
- Input byte buffer.output
- Output character buffer.- Throws:
EncodingException
- on encoding errors.
-
finalize
Description copied from interface:Encoder
Performs final output encoding (e.g. padding) after all input bytes have been provided.- Specified by:
finalize
in interfaceEncoder
- Parameters:
output
- Output character buffer.- Throws:
EncodingException
- on encoding errors.
-
outputSize
public int outputSize(int inputSize) Description copied from interface:Encoder
Expected number of characters in the output buffer for an input buffer of the given size.- Specified by:
outputSize
in interfaceEncoder
- Parameters:
inputSize
- Size of input buffer in bytes.- Returns:
- Minimum character buffer size required to store all encoded input bytes.
-