Class HexDecoder

java.lang.Object
org.cryptacular.codec.HexDecoder
All Implemented Interfaces:
Decoder

public class HexDecoder extends Object implements Decoder
Stateful hexadecimal character-to-byte decoder.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    Number of encoded characters processed.
    private static final byte[]
    Hex character decoding table.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    decode(CharBuffer input, ByteBuffer output)
    Decodes characters in input buffer into bytes placed in the output buffer.
    void
    Performs final output decoding (e.g.
    private static byte
    lookup(char c)
    Looks up the byte that corresponds to the given character.
    int
    outputSize(int inputSize)
    Expected number of bytes in the output buffer for an input buffer of the given size.

    Methods inherited from class java.lang.Object

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

    • DECODING_TABLE

      private static final byte[] DECODING_TABLE
      Hex character decoding table.
    • count

      private int count
      Number of encoded characters processed.
  • Constructor Details

    • HexDecoder

      public HexDecoder()
  • Method Details

    • decode

      public void decode(CharBuffer input, ByteBuffer output) throws EncodingException
      Description copied from interface: Decoder
      Decodes characters in input buffer into bytes placed in the output buffer. This method may be called multiple times, followed by Decoder.finalize(ByteBuffer). after all input bytes have been provided.
      Specified by:
      decode in interface Decoder
      Parameters:
      input - Input character buffer.
      output - Output byte buffer.
      Throws:
      EncodingException - on decoding errors.
    • finalize

      public void finalize(ByteBuffer output) throws EncodingException
      Description copied from interface: Decoder
      Performs final output decoding (e.g. padding) after all input characters have been provided.
      Specified by:
      finalize in interface Decoder
      Parameters:
      output - Output byte buffer.
      Throws:
      EncodingException - on decoding errors.
    • outputSize

      public int outputSize(int inputSize)
      Description copied from interface: Decoder
      Expected number of bytes in the output buffer for an input buffer of the given size.
      Specified by:
      outputSize in interface Decoder
      Parameters:
      inputSize - Size of input buffer in characters.
      Returns:
      Minimum byte buffer size required to store all decoded characters in input buffer.
    • lookup

      private static byte lookup(char c)
      Looks up the byte that corresponds to the given character.
      Parameters:
      c - Encoded character.
      Returns:
      Decoded byte.