Class AbstractRFC1522Codec

java.lang.Object
com.helger.base.codec.impl.AbstractRFC1522Codec
All Implemented Interfaces:
ICodec<String>, IDecoder<String,String>, IEncoder<String,String>
Direct Known Subclasses:
RFC1522BCodec, RFC1522QCodec

public abstract class AbstractRFC1522Codec extends Object implements ICodec<String>
Implements methods common to all codecs defined in RFC 1522.

RFC 1522 describes techniques to allow the encoding of non-ASCII text in various portions of a RFC 822 [2] message header, in a manner which is unlikely to confuse existing message handling software.

This class is immutable and thread-safe.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
    Postfix.
    protected static final String
    Prefix.
    protected static final char
    Separator.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractRFC1522Codec(@NonNull Charset aCharset)
    Constructor which allows for the selection of a default charset
  • Method Summary

    Modifier and Type
    Method
    Description
    @NonNull Charset
     
    protected abstract byte @Nullable []
    getDecoded(byte @Nullable [] aEncodedBuffer, int nOfs, int nLen)
     
    @Nullable String
    getDecoded(@Nullable String sEncodedText)
    Applies an RFC 1522 compliant decoding scheme to the given string of text.
    protected abstract byte @Nullable []
    getEncoded(byte @Nullable [] aDecodedBuffer, int nOfs, int nLen)
     
    @Nullable String
    getEncoded(@Nullable String sText)
    Applies an RFC 1522 compliant encoding scheme to the given string of text with the given charset.
    protected abstract @NonNull @Nonempty String
    Returns the codec name (referred to as encoding in the RFC 1522).

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • AbstractRFC1522Codec

      protected AbstractRFC1522Codec(@NonNull Charset aCharset)
      Constructor which allows for the selection of a default charset
      Parameters:
      aCharset - the default string charset to use.
  • Method Details

    • getCharset

      public @NonNull Charset getCharset()
      Returns:
      The charset used for string decoding and encoding. Never null.
    • getRFC1522Encoding

      @Nonempty protected abstract @NonNull @Nonempty String getRFC1522Encoding()
      Returns the codec name (referred to as encoding in the RFC 1522).
      Returns:
      name of the codec
    • getEncoded

      @ReturnsMutableCopy protected abstract byte @Nullable [] getEncoded(byte @Nullable [] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen)
    • getDecoded

      @ReturnsMutableCopy protected abstract byte @Nullable [] getDecoded(byte @Nullable [] aEncodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen)
    • getEncoded

      public @Nullable String getEncoded(@Nullable String sText)
      Applies an RFC 1522 compliant encoding scheme to the given string of text with the given charset.

      This method constructs the "encoded-word" header common to all the RFC 1522 codecs and then invokes #getEncoded(byte []) method of a concrete class to perform the specific encoding.

      Specified by:
      getEncoded in interface IEncoder<String,String>
      Parameters:
      sText - a string to encode
      Returns:
      RFC 1522 compliant "encoded-word"
      Throws:
      EncodeException - thrown if there is an error condition during the Encoding process.
      See Also:
    • getDecoded

      public @Nullable String getDecoded(@Nullable String sEncodedText)
      Applies an RFC 1522 compliant decoding scheme to the given string of text.

      This method processes the "encoded-word" header common to all the RFC 1522 codecs and then invokes #getDecoded(byte []) method of a concrete class to perform the specific decoding.

      Specified by:
      getDecoded in interface IDecoder<String,String>
      Parameters:
      sEncodedText - a string to decode
      Returns:
      A new decoded String or null if the input is null.
      Throws:
      DecodeException - thrown if there is an error condition during the decoding process.