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 int
Number of base64 characters per line. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBaseNEncoder
(char[] characterSet, int charactersPerLine) Creates a new instance with given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
encode
(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.void
finalize
(CharBuffer output) Performs final output encoding (e.g.protected abstract int
protected abstract int
boolean
int
outputSize
(int inputSize) Expected number of characters in the output buffer for an input buffer of the given size.void
setPaddedOutput
(boolean enabled) Sets the output padding mode.
-
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.
-
-
Method Details
-
isPaddedOutput
public boolean isPaddedOutput()- Returns:
- True if padded output is enabled (default), false otherwise.
-
setPaddedOutput
public void setPaddedOutput(boolean enabled) Sets the output padding mode.- Parameters:
enabled
- True to enable padded output, false otherwise.
-
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.
-
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.
-