Package org.cryptacular.codec
Class HexEncoder
java.lang.Object
org.cryptacular.codec.HexEncoder
- All Implemented Interfaces:
Encoder
Stateless hexadecimal byte-to-character encoder.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanFlag indicating whether to delimit every two characters with ':' as in key fingerprints, etc.private static final char[]Lowercase hex character encoding table.private final char[]Encoding table to use.private static final char[]Uppercase hex character encoding table. -
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 TypeMethodDescriptionvoidencode(ByteBuffer input, CharBuffer output) Encodes bytes in input buffer into characters placed in the output buffer.voidfinalize(CharBuffer output) Performs final output encoding (e.g.private static voidInitializes the encoding table for the given character set.intoutputSize(int inputSize) Expected number of characters in the output buffer for an input buffer of the given size.
-
Field Details
-
LC_ENCODING_TABLE
private static final char[] LC_ENCODING_TABLELowercase hex character encoding table. -
UC_ENCODING_TABLE
private static final char[] UC_ENCODING_TABLEUppercase hex character encoding table. -
delimit
private final boolean delimitFlag indicating whether to delimit every two characters with ':' as in key fingerprints, etc. -
table
private final char[] tableEncoding table to use.
-
-
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:EncoderEncodes 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:
encodein interfaceEncoder- Parameters:
input- Input byte buffer.output- Output character buffer.- Throws:
EncodingException- on encoding errors.
-
finalize
Description copied from interface:EncoderPerforms final output encoding (e.g. padding) after all input bytes have been provided.- Specified by:
finalizein interfaceEncoder- Parameters:
output- Output character buffer.- Throws:
EncodingException- on encoding errors.
-
outputSize
public int outputSize(int inputSize) Description copied from interface:EncoderExpected number of characters in the output buffer for an input buffer of the given size.- Specified by:
outputSizein interfaceEncoder- Parameters:
inputSize- Size of input buffer in bytes.- Returns:
- Minimum character buffer size required to store all encoded input bytes.
-
initTable
Initializes the encoding table for the given character set.- Parameters:
charset- Character set.table- Encoding table.
-