Class HexEncoder

java.lang.Object
org.cryptacular.codec.HexEncoder
All Implemented Interfaces:
Encoder

public class HexEncoder extends Object implements Encoder
Stateless hexadecimal byte-to-character encoder.
Author:
Middleware Services
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance that does not delimit bytes in the output hex string.
    HexEncoder(boolean delimitBytes)
    Creates a new instance with optional colon-delimiting of bytes.
    HexEncoder(boolean delimitBytes, boolean uppercase)
    Creates a new instance with optional colon-delimiting of bytes and uppercase output.
  • 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.
    void
    Performs final output encoding (e.g.
    int
    outputSize(int inputSize)
    Expected number of characters 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
  • Constructor Details

    • HexEncoder

      public HexEncoder()
      Creates a new instance that does not delimit bytes in the output hex string.
    • HexEncoder

      public HexEncoder(boolean delimitBytes)
      Creates a new instance with optional colon-delimiting of bytes.
      Parameters:
      delimitBytes - True to delimit every two characters (i.e. every byte) with ':' character.
    • HexEncoder

      public HexEncoder(boolean delimitBytes, boolean uppercase)
      Creates a new instance with optional colon-delimiting of bytes and uppercase output.
      Parameters:
      delimitBytes - True to delimit every two characters (i.e. every byte) with ':' character.
      uppercase - True to output uppercase alphabetic characters, false for lowercase.
  • Method Details

    • 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.