i2p.susi.webmail.encoding

## Class Encoding

- java.lang.Object
- - i2p.susi.webmail.encoding.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.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `_log` Logger for the encoding subclass.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Encoding()` Creates an Encoding with a logger.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Buffer` | `decode(Buffer in)` Decode a buffer into another buffer.
    `void` | `decode(Buffer in, Buffer out)` Decode a buffer into another buffer using the input stream.
    `Buffer` | `decode(byte[] in)` Decode a byte array using default offset and length.
    `Buffer` | `decode(byte[] in, int offset, int length)` Decode a portion of a byte array.
    `abstract void` | `decode(InputStream in, Buffer out)` Decode an input stream into a buffer.
    `Buffer` | `decode(String str)` Decode a string.
    `abstract String` | `encode(byte[] in)` Encode a byte array to a ASCII or ISO-8859-1 String.
    `void` | `encode(InputStream in, Writer out)` Encode an input stream of bytes to a ASCII or ISO-8859-1 String.
    `String` | `encode(String str)` Encode a (UTF-8) String to a ASCII or ISO-8859-1 String.
    `abstract String` | `getName()` Returns the name of this encoding.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _log

          protected final Log _log

      Logger for the encoding subclass.

  - ### Constructor Detail

    - #### Encoding

          protected Encoding()

      Creates an Encoding with a logger.

  - ### Method Detail

    - #### decode

          public Buffer decode(Buffer in)
                        throws IOException

      Decode a buffer into another buffer. This implementation just calls decode(in.content, in.offset, in.length). Most classes will not need to override.
      Parameters:
        `in` - the buffer containing data to decode
      Returns:
        a buffer containing the decoded data
      Throws:
        `DecodingException` - if decoding fails
        `IOException`
      See Also:
        `decode(byte[], int, int)`

    - #### decode

          public void decode(Buffer in,
                             Buffer out)
                      throws IOException

      Decode a buffer into another buffer using the input stream.
      Parameters:
        `in` - the buffer containing data to decode
        `out` - the buffer to write decoded data to
      Throws:
        `DecodingException` - if decoding fails
        `IOException` - if reading from input stream fails
      See Also:
        `decode(byte[], int, int)`

    - #### decode

          public Buffer decode(byte[] in)
                        throws DecodingException

      Decode a byte array using default offset and length. This implementation just calls decode(in, 0, in.length). Most classes will not need to override.
      Parameters:
        `in` - the byte array to decode
      Returns:
        a buffer containing the decoded data
      Throws:
        `DecodingException` - if decoding fails
      See Also:
        `decode(byte[], int, int)`

    - #### decode

          public Buffer decode(byte[] in,
                               int offset,
                               int length)
                        throws DecodingException

      Decode a portion of a byte array.
      Parameters:
        `in` - the byte array to decode
        `offset` - the starting position in the array
        `length` - the number of bytes to decode
      Returns:
        a buffer containing the decoded data as a String
      Throws:
        `DecodingException` - if decoding fails

    - #### decode

          public abstract void decode(InputStream in,
                                      Buffer out)
                               throws IOException

      Decode an input stream into a buffer.
      Parameters:
        `in` - the input stream to read data from
        `out` - the buffer to write decoded data to
      Throws:
        `DecodingException` - if decoding fails
        `IOException` - if reading from input stream fails
      See Also:
        `decode(byte[], int, int)`

    - #### decode

          public Buffer decode(String str)
                        throws DecodingException

      Decode a string. This implementation just converts the string to a byte array and then calls decode(byte[]). Most classes will not need to override.
      Parameters:
        `str` - the string to decode
      Returns:
        a buffer containing the decoded data, or null if str is null
      Throws:
        `DecodingException` - if decoding fails
      See Also:
        `decode(byte[], int, int)`

    - #### 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` - the byte array to encode
      Returns:
        the encoded string, SMTP-safe
      Throws:
        `EncodingException` - if encoding fails

    - #### 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.
      Parameters:
        `in` - the input stream to encode
        `out` - the writer to write encoded output to
      Throws:
        `IOException` - if reading from stream or writing fails

    - #### 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` - the string to encode
      Throws:
        `EncodingException` - if encoding fails
      See Also:
        `encode(byte[])`

    - #### getName

          public abstract String getName()

      Returns the name of this encoding.
      Returns:
        the encoding name