public class

QCodec

extends Object
implements StringDecoder StringEncoder
java.lang.Object
   ↳ org.apache.commons.codec.net.QCodec

Class Overview

Similar to the Quoted-Printable content-transfer-encoding defined in RFC 1521 and designed to allow text containing mostly ASCII characters to be decipherable on an ASCII terminal without decoding.

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.

Summary

Constants
String POSTFIX Prefix
String PREFIX Postfix
char SEP Separator.
Public Constructors
QCodec()
Default constructor.
QCodec(String charset)
Constructor which allows for the selection of a default charset
Public Methods
Object decode(Object pObject)
Decodes a quoted-printable object into its original form.
String decode(String pString)
Decodes a quoted-printable string into its original form.
Object encode(Object pObject)
Encodes an object into its quoted-printable form using the default charset.
String encode(String pString, String charset)
Encodes a string into its quoted-printable form using the specified charset.
String encode(String pString)
Encodes a string into its quoted-printable form using the default charset.
String getDefaultCharset()
The default charset used for string decoding and encoding.
boolean isEncodeBlanks()
Tests if optional tranformation of SPACE characters is to be used
void setEncodeBlanks(boolean b)
Defines whether optional tranformation of SPACE characters is to be used
Protected Methods
String decodeText(String text)
Applies an RFC 1522 compliant decoding scheme to the given string of text.
byte[] doDecoding(byte[] bytes)
Decodes an array of bytes using the defined encoding scheme
byte[] doEncoding(byte[] bytes)
Encodes an array of bytes using the defined encoding scheme
String encodeText(String text, String charset)
Applies an RFC 1522 compliant encoding scheme to the given string of text with the given charset.
String getEncoding()
Returns the codec name (referred to as encoding in the RFC 1522)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.commons.codec.Decoder
From interface org.apache.commons.codec.Encoder
From interface org.apache.commons.codec.StringDecoder
From interface org.apache.commons.codec.StringEncoder

Constants

protected static final String POSTFIX

Prefix

Constant Value: "?="

protected static final String PREFIX

Postfix

Constant Value: "=?"

protected static final char SEP

Separator.

Constant Value: 63 (0x0000003f)

Public Constructors

public QCodec ()

Default constructor.

public QCodec (String charset)

Constructor which allows for the selection of a default charset

Parameters
charset the default string charset to use.

Public Methods

public Object decode (Object pObject)

Decodes a quoted-printable object into its original form. Escaped characters are converted back to their original representation.

Parameters
pObject quoted-printable object to convert into its original form
Returns
  • original object
Throws
DecoderException Thrown if the argument is not a String. Thrown if a failure condition is encountered during the decode process.

public String decode (String pString)

Decodes a quoted-printable string into its original form. Escaped characters are converted back to their original representation.

Parameters
pString quoted-printable string to convert into its original form
Returns
  • original string
Throws
DecoderException A decoder exception is thrown if a failure condition is encountered during the decode process.

public Object encode (Object pObject)

Encodes an object into its quoted-printable form using the default charset. Unsafe characters are escaped.

Parameters
pObject object to convert to quoted-printable form
Returns
  • quoted-printable object
Throws
EncoderException thrown if a failure condition is encountered during the encoding process.

public String encode (String pString, String charset)

Encodes a string into its quoted-printable form using the specified charset. Unsafe characters are escaped.

Parameters
pString string to convert to quoted-printable form
charset the charset for pString
Returns
  • quoted-printable string
Throws
EncoderException thrown if a failure condition is encountered during the encoding process.

public String encode (String pString)

Encodes a string into its quoted-printable form using the default charset. Unsafe characters are escaped.

Parameters
pString string to convert to quoted-printable form
Returns
  • quoted-printable string
Throws
EncoderException thrown if a failure condition is encountered during the encoding process.

public String getDefaultCharset ()

The default charset used for string decoding and encoding.

Returns
  • the default string charset.

public boolean isEncodeBlanks ()

Tests if optional tranformation of SPACE characters is to be used

Returns
  • true if SPACE characters are to be transformed, false otherwise

public void setEncodeBlanks (boolean b)

Defines whether optional tranformation of SPACE characters is to be used

Parameters
b true if SPACE characters are to be transformed, false otherwise

Protected Methods

protected String decodeText (String text)

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 doEncoding(byte[]) method of a concrete class to perform the specific deconding.

Parameters
text a string to decode
Returns
  • A new decoded String or null if the input is null.
Throws
DecoderException thrown if there is an error conidition during the Decoding process.
UnsupportedEncodingException thrown if charset specified in the "encoded-word" header is not supported

protected byte[] doDecoding (byte[] bytes)

Decodes an array of bytes using the defined encoding scheme

Parameters
bytes Data to be decoded
Returns
  • a byte array that contains decoded data

protected byte[] doEncoding (byte[] bytes)

Encodes an array of bytes using the defined encoding scheme

Parameters
bytes Data to be encoded
Returns
  • A byte array containing the encoded data

protected String encodeText (String text, String charset)

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 doEncoding(byte[]) method of a concrete class to perform the specific enconding.

Parameters
text a string to encode
charset a charset to be used
Returns
  • RFC 1522 compliant "encoded-word"
Throws
EncoderException thrown if there is an error conidition during the Encoding process.
UnsupportedEncodingException thrown if charset is not supported

protected String getEncoding ()

Returns the codec name (referred to as encoding in the RFC 1522)

Returns
  • name of the codec