Class AbstractBaseNEncoder

java.lang.Object
org.cryptacular.codec.AbstractBaseNEncoder
All Implemented Interfaces:
Encoder
Direct Known Subclasses:
Base32Encoder, Base64Encoder

public abstract class AbstractBaseNEncoder extends Object implements Encoder
Base encoder class for encoding schemes described in RFC 3548.
Author:
Middleware Services
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    Number of base64 characters per line.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractBaseNEncoder(char[] characterSet, int charactersPerLine)
    Creates a new instance with given parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lineLength

      protected final int lineLength
      Number 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

      public void encode(ByteBuffer input, CharBuffer output) throws EncodingException
      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 by Encoder.finalize(java.nio.CharBuffer) after all input bytes have been provided.
      Specified by:
      encode in interface Encoder
      Parameters:
      input - Input byte buffer.
      output - Output character buffer.
      Throws:
      EncodingException - on encoding errors.
    • finalize

      public void finalize(CharBuffer output) throws EncodingException
      Description copied from interface: Encoder
      Performs final output encoding (e.g. padding) after all input bytes have been provided.
      Specified by:
      finalize in interface Encoder
      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 interface Encoder
      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

      protected static char[] encodingTable(String alphabet, int n)
      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.