cryptix.util.mime
Class QuotedPrintable

java.lang.Object
  |
  +--cryptix.util.mime.TransferEncoding
        |
        +--cryptix.util.mime.QuotedPrintable

public class QuotedPrintable
extends TransferEncoding

This class provides methods for encoding and decoding data in MIME quoted-printable format, as described in RFC 2045 (Section 6.7).

QuotedPrintable is a Content-Transfer-Encoding. That is, the input to encoding is a sequence of bytes, and the output is a sequence of characters (similar to base64). It is orthogonal to the character encoding.

For example, suppose a MIME message consists of Unicode text with a Content-Type of "text/plain; charset=UTF8", and a Content-Transfer-Encoding of "quoted-printable" (this would be unusual, but valid). A MIME message should be viewed as a sequence of abstract characters, which in this case could be decoded as bytes according to the "quoted-printable" transfer encoding, and then back to a (different, in general) sequence of characters according to the "UTF8" character encoding.

The input to the encode methods is always a byte array. Strictly speaking the output represents a sequence of characters, but since these characters are from a subset of both the Unicode and ASCII character repertoires, it is possible to express the output either as a String or as a byte array.

References:

  1. RFC 2045, Multipurpose Internet Mail Extensions (MIME) Part One, Format of Internet Message Bodies, "Section 6.7 Quoted-Printable Content-Transfer-Encoding," http://www.imc.org/rfc2045

  2. Dan Connolly, draft-ietf-html-charset-harmful-00.txt, "Character Set" Considered Harmful, http://www.w3.org/pub/WWW/MarkUp/html-spec/charset-harmful.html

Copyright © 1995-1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.2 $

Since:
Cryptix 3.0.2
Author:
Jill Baker

Constructor Summary
QuotedPrintable()
           
 
Method Summary
 byte[] decode(java.lang.String s)
          Takes a quoted-printable encoding and decodes it to find the corresponding sequence of bytes.
 java.lang.String encode(byte[] b)
          Encodes a byte array using quoted-printable encoding, and returns the result as a String.
static boolean isProbablyEncoded(byte[] buf)
          Tests whether or not an encoding could have been generated by encodeAsByteArray() or any similar generator that complies with the RFC.
static boolean isProbablyEncoded(java.lang.String s)
          Tests whether or not an encoding, expressed as if it were an ASCII String, could have been generated by encode() or any similar generator that complies with the RFC.
 
Methods inherited from class cryptix.util.mime.TransferEncoding
decode, encodeAsByteArray
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuotedPrintable

public QuotedPrintable()
Method Detail

encode

public java.lang.String encode(byte[] b)
Encodes a byte array using quoted-printable encoding, and returns the result as a String.

Line breaks in the input MUST be represented as "\r\n" - any other combination is treated as binary data. Line breaks in the output will always be represented as "\r\n".

Overrides:
encode in class TransferEncoding
Parameters:
b - canonical data to be encoded
Returns:
output in quoted-printable form.

decode

public byte[] decode(java.lang.String s)
Takes a quoted-printable encoding and decodes it to find the corresponding sequence of bytes.

Unrecognised sequences starting with '=' are passed through unmodified, as are characters that do not correspond to bytes that could have been output by a correct quoted-printable encoder. Note that this method will strip trailing whitespace from each line.

Overrides:
decode in class TransferEncoding
Parameters:
s - input string in quoted-printable form
Returns:
the decoded data.

isProbablyEncoded

public static boolean isProbablyEncoded(java.lang.String s)
Tests whether or not an encoding, expressed as if it were an ASCII String, could have been generated by encode() or any similar generator that complies with the RFC.

isProbablyEncoded

public static boolean isProbablyEncoded(byte[] buf)
Tests whether or not an encoding could have been generated by encodeAsByteArray() or any similar generator that complies with the RFC.