Package org.cryptacular.codec
Class AbstractBaseNEncoder
java.lang.Object
org.cryptacular.codec.AbstractBaseNEncoder
- All Implemented Interfaces:
Encoder
- Direct Known Subclasses:
Base32Encoder,Base64Encoder
Base encoder class for encoding schemes described in RFC 3548.
- Author:
- Middleware Services
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intNumber of base64 characters per line. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBaseNEncoder(char[] characterSet, int charactersPerLine) Creates a new instance with given parameters.AbstractBaseNEncoder(char[] charset, int charactersPerLine, boolean paddedOutput) Creates a new instance with given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidencode(ByteBuffer input, CharBuffer output) Encodes bytes in input buffer into characters placed in the output buffer.protected static char[]encodingTable(String alphabet, int n) Converts the given alphabet into a base-N encoding table.voidfinalize(CharBuffer output) Performs final output encoding (e.g. padding) after all input bytes have been provided.protected abstract intprotected abstract intbooleanintoutputSize(int inputSize) Expected number of characters in the output buffer for an input buffer of the given size.
-
Field Details
-
lineLength
protected final int lineLengthNumber of base64 characters per line.
-
-
Constructor Details
-
AbstractBaseNEncoder
public AbstractBaseNEncoder(char[] characterSet, int charactersPerLine) Creates a new instance with given parameters.- Parameters:
characterSet- Encoding character set.charactersPerLine- Number of characters per line.
-
AbstractBaseNEncoder
public AbstractBaseNEncoder(char[] charset, int charactersPerLine, boolean paddedOutput) Creates a new instance with given parameters.- Parameters:
charset- Encoding character set.charactersPerLine- Number of characters per line.paddedOutput- True to enable padded output, false otherwise.
-
-
Method Details
-
isPaddedOutput
public boolean isPaddedOutput()- Returns:
- True if padded output is enabled (default), false otherwise.
-
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.
-
getBlockLength
protected abstract int getBlockLength()- Returns:
- Number of bits in a block of encoded characters.
-
getBitsPerChar
protected abstract int getBitsPerChar()- Returns:
- Number of bits encoding a single character.
-
encodingTable
Converts the given alphabet into a base-N encoding table.- Parameters:
alphabet- Encoding alphabet to use.n- Encoding base.- Returns:
- Encoding table of N elements.
-