Class Encoding

  • Direct Known Subclasses:
    Base64, EightBit, HeaderLine, HTML, QuotedPrintable, SevenBit

    public abstract class Encoding
    extends Object
    Interface to encode/decode content transfer encodings like quoted-printable, base64 etc.
    Since:
    0.9.33 changed from interface to abstract class
    Author:
    susi
    • Field Detail

      • _log

        protected final Log _log
    • Constructor Detail

      • Encoding

        protected Encoding()
    • Method Detail

      • getName

        public abstract String getName()
      • encode

        public abstract String encode​(byte[] in)
                               throws EncodingException
        Encode a byte array to a ASCII or ISO-8859-1 String. Output must be SMTP-safe: Line length of 998 or less, using SMTP-safe characters, followed by \r\n, and must not start with a '.' unless escaped by a 2nd dot. For some encodings, max line length is 76.
        Parameters:
        in -
        Returns:
        Encoded string.
        Throws:
        EncodingException
      • encode

        public String encode​(String str)
                      throws EncodingException
        Encode a (UTF-8) String to a ASCII or ISO-8859-1 String. Output must be SMTP-safe: Line length of 998 or less, using SMTP-safe characters, followed by \r\n, and must not start with a '.' unless escaped by a 2nd dot. For some encodings, max line length is 76. This implementation just converts the string to a byte array and then calls encode(byte[]). Most classes will not need to override.
        Parameters:
        str -
        Throws:
        EncodingException
        Since:
        0.9.33 implementation moved from subclasses
        See Also:
        encode(byte[])
      • encode

        public void encode​(InputStream in,
                           Writer out)
                    throws IOException
        Encode an input stream of bytes to a ASCII or ISO-8859-1 String. Output must be SMTP-safe: Line length of 998 or less, using SMTP-safe characters, followed by \r\n, and must not start with a '.' unless escaped by a 2nd dot. For some encodings, max line length is 76. This implementation just reads the whole stream into memory and then calls encode(byte[]). Subclasses should implement a more memory-efficient method if large inputs are expected.
        Throws:
        IOException
        Since:
        0.9.33
      • decode

        public Buffer decode​(byte[] in,
                             int offset,
                             int length)
                      throws DecodingException
        Parameters:
        in -
        offset -
        length -
        Returns:
        Output buffer containing decoded String.
        Throws:
        DecodingException
      • decode

        public Buffer decode​(String str)
                      throws DecodingException
        This implementation just converts the string to a byte array and then calls decode(byte[]). Most classes will not need to override.
        Parameters:
        str -
        Returns:
        null if str is null
        Throws:
        DecodingException
        Since:
        0.9.33 implementation moved from subclasses
        See Also:
        decode(byte[], int, int)