public class Base16 extends BaseNCodec
This class is thread-safe.
This implementation strictly follows RFC 4648, and as such unlike
the Base32
and Base64
implementations,
it does not ignore invalid alphabet characters or whitespace,
neither does it offer chunking or padding characters.
The only additional feature above those specified in RFC 4648 is support for working with a lower-case alphabet in addition to the default upper-case alphabet.
BaseNCodec.Context
Modifier and Type | Field and Description |
---|---|
private static int |
BITS_PER_ENCODED_BYTE
BASE16 characters are 4 bits in length.
|
private static int |
BYTES_PER_ENCODED_BLOCK |
private static int |
BYTES_PER_UNENCODED_BLOCK |
private byte[] |
decodeTable
Decode table to use.
|
private byte[] |
encodeTable
Encode table to use.
|
private static byte[] |
LOWER_CASE_DECODE_TABLE
This array is a lookup table that translates Unicode characters drawn from the a lower-case "Base16 Alphabet"
into their 4-bit positive integer equivalents.
|
private static byte[] |
LOWER_CASE_ENCODE_TABLE
This array is a lookup table that translates 4-bit positive integer index values into their "Base16 Alphabet"
lower-case equivalents.
|
private static int |
MASK_4BITS
Mask used to extract 4 bits, used when decoding character.
|
private static byte[] |
UPPER_CASE_DECODE_TABLE
This array is a lookup table that translates Unicode characters drawn from the "Base16 Alphabet" (as specified
in Table 5 of RFC 4648) into their 4-bit positive integer equivalents.
|
private static byte[] |
UPPER_CASE_ENCODE_TABLE
This array is a lookup table that translates 4-bit positive integer index values into their "Base16 Alphabet"
equivalents as specified in Table 5 of RFC 4648.
|
CHUNK_SEPARATOR, DECODING_POLICY_DEFAULT, EOF, lineLength, MASK_8BITS, MIME_CHUNK_SIZE, pad, PAD, PAD_DEFAULT, PEM_CHUNK_SIZE
Constructor and Description |
---|
Base16()
Creates a Base16 codec used for decoding and encoding.
|
Base16(boolean lowerCase)
Creates a Base16 codec used for decoding and encoding.
|
Base16(boolean lowerCase,
CodecPolicy decodingPolicy)
Creates a Base16 codec used for decoding and encoding.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
decode(byte[] data,
int offset,
int length,
BaseNCodec.Context context) |
private int |
decodeOctet(byte octet) |
(package private) void |
encode(byte[] data,
int offset,
int length,
BaseNCodec.Context context) |
boolean |
isInAlphabet(byte octet)
Returns whether or not the
octet is in the Base16 alphabet. |
private void |
validateTrailingCharacter()
Validates whether decoding allows an entire final trailing character that cannot be
used for a complete byte.
|
available, containsAlphabetOrPad, decode, decode, decode, encode, encode, encode, encodeAsString, encodeToString, ensureBufferSize, getChunkSeparator, getCodecPolicy, getDefaultBufferSize, getEncodedLength, hasData, isInAlphabet, isInAlphabet, isStrictDecoding, isWhiteSpace, readResults
private static final int BITS_PER_ENCODED_BYTE
private static final int BYTES_PER_ENCODED_BLOCK
private static final int BYTES_PER_UNENCODED_BLOCK
private static final byte[] UPPER_CASE_DECODE_TABLE
private static final byte[] UPPER_CASE_ENCODE_TABLE
private static final byte[] LOWER_CASE_DECODE_TABLE
private static final byte[] LOWER_CASE_ENCODE_TABLE
private static final int MASK_4BITS
private final byte[] decodeTable
private final byte[] encodeTable
public Base16()
public Base16(boolean lowerCase)
lowerCase
- if true
then use a lower-case Base16 alphabet.public Base16(boolean lowerCase, CodecPolicy decodingPolicy)
lowerCase
- if true
then use a lower-case Base16 alphabet.decodingPolicy
- Decoding policy.void decode(byte[] data, int offset, int length, BaseNCodec.Context context)
decode
in class BaseNCodec
private int decodeOctet(byte octet)
void encode(byte[] data, int offset, int length, BaseNCodec.Context context)
encode
in class BaseNCodec
public boolean isInAlphabet(byte octet)
octet
is in the Base16 alphabet.isInAlphabet
in class BaseNCodec
octet
- The value to test.true
if the value is defined in the the Base16 alphabet false
otherwise.private void validateTrailingCharacter()
java.lang.IllegalArgumentException
- if strict decoding is enabled