java.lang.Object
i2p.susi.webmail.encoding.Encoding
Direct Known Subclasses:
Base64, EightBit, HeaderLine, HTML, QuotedPrintable, SevenBit

public abstract class Encodingextends Object
Interface to encode/decode content transfer encodings like quoted-printable, base64 etc.
  • Field Details

    • _log

      protected final Log _log
      Logger for the encoding subclass.
  • Constructor Details

    • Encoding

      protected Encoding()
      Creates an Encoding with a logger.
  • Method Details

    • getName

      public abstract String getName()
      Returns the name of this encoding.
      Returns:
      the encoding name
    • 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 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
      Returns:
      the encoded string, SMTP-safe
      Throws:
      EncodingException - if encoding fails
      See Also:
    • 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
    • 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

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

      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

      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

      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: