Class Base16Codec

java.lang.Object
com.helger.base.codec.impl.Base16Codec
All Implemented Interfaces:
IByteArrayCodec, IByteArrayDecoder, IByteArrayEncoder, IByteArrayStreamDecoder, IByteArrayStreamEncoder, ICodec<byte[]>, IDecoder<byte[],byte[]>, IEncoder<byte[],byte[]>

public class Base16Codec extends Object implements IByteArrayCodec
Base16 encoder and decoder.
Author:
Philip Helger
  • Constructor Details

    • Base16Codec

      public Base16Codec()
      Creates a Base16 codec used for decoding and encoding.
  • Method Details

    • getMaximumEncodedLength

      @Nonnegative public int getMaximumEncodedLength(@Nonnegative int nDecodedLen)
      Description copied from interface: IByteArrayEncoder
      Get the maximum encoded length based on the provided decoded length. This is purely for performance reasons. The name of the method would be better called "getMaximumEncodedLength".
      Specified by:
      getMaximumEncodedLength in interface IByteArrayEncoder
      Specified by:
      getMaximumEncodedLength in interface IByteArrayStreamEncoder
      Parameters:
      nDecodedLen - The decoded length. Always ≥ 0.
      Returns:
      The maximum encoded length. Always ≥ 0.
    • encode

      public void encode(@WillNotClose @NonNull InputStream aDecodedIS, @WillNotClose @NonNull OutputStream aOS)
      Encode data from the input stream and write the Base16 encoded result to the output stream.
      Parameters:
      aDecodedIS - The decoded input stream to read from. May not be null.
      aOS - The output stream to write the encoded data to. May not be null.
    • encode

      public void encode(byte @Nullable [] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull OutputStream aOS)
      Encode the passed decoded buffer to Base16 and write it to the output stream.
      Specified by:
      encode in interface IByteArrayStreamEncoder
      Parameters:
      aDecodedBuffer - The buffer to be encoded. May be null.
      nOfs - The offset in the buffer to start encoding from.
      nLen - The number of bytes to encode.
      aOS - The output stream to write the encoded data to. May not be null.
    • getMaximumDecodedLength

      @Nonnegative public int getMaximumDecodedLength(@Nonnegative int nEncodedLen)
      Description copied from interface: IByteArrayDecoder
      Get the maximum decoded length based on the provided encoded length. This is purely for performance reasons.
      Specified by:
      getMaximumDecodedLength in interface IByteArrayDecoder
      Parameters:
      nEncodedLen - The encoded length. Always ≥ 0.
      Returns:
      The maximum decoded length. Always ≥ 0.
    • decode

      public void decode(@WillNotClose @NonNull InputStream aEncodedIS, @WillNotClose @NonNull OutputStream aOS)
      Decode data from the Base16 encoded input stream and write the decoded result to the output stream.
      Parameters:
      aEncodedIS - The Base16 encoded input stream to read from. May not be null.
      aOS - The output stream to write the decoded data to. May not be null.
    • decode

      public void decode(byte @Nullable [] aEncodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull OutputStream aOS)
      Decode the passed Base16 encoded buffer and write the decoded bytes to the output stream.
      Specified by:
      decode in interface IByteArrayStreamDecoder
      Parameters:
      aEncodedBuffer - The Base16 encoded buffer to be decoded. May be null.
      nOfs - The offset in the buffer to start decoding from.
      nLen - The number of bytes to decode.
      aOS - The output stream to write the decoded data to. May not be null.