org.apache.commons.codec.net

Class BCodec

public class BCodec extends RFC1522Codec implements StringEncoder, StringDecoder

Identical to the Base64 encoding defined by RFC 1521 and allows a character set to be specified.

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.

Since: 1.3

Version: $Id: BCodec.java 130357 2004-04-13 22:46:37Z ggregory $

Author: Apache Software Foundation

See Also: MIME (Multipurpose Internet Mail Extensions) Part Two: Message Header Extensions for Non-ASCII Text

Field Summary
Stringcharset
The default charset used for string decoding and encoding.
Constructor Summary
BCodec()
Default constructor.
BCodec(String charset)
Constructor which allows for the selection of a default charset
Method Summary
Stringdecode(String value)
Decodes a Base64 string into its original form.
Objectdecode(Object value)
Decodes a Base64 object into its original form.
protected byte[]doDecoding(byte[] bytes)
protected byte[]doEncoding(byte[] bytes)
Stringencode(String value, String charset)
Encodes a string into its Base64 form using the specified charset.
Stringencode(String value)
Encodes a string into its Base64 form using the default charset.
Objectencode(Object value)
Encodes an object into its Base64 form using the default charset.
StringgetDefaultCharset()
The default charset used for string decoding and encoding.
protected StringgetEncoding()

Field Detail

charset

private String charset
The default charset used for string decoding and encoding.

Constructor Detail

BCodec

public BCodec()
Default constructor.

BCodec

public BCodec(String charset)
Constructor which allows for the selection of a default charset

Parameters: charset the default string charset to use.

See Also: JRE character encoding names

Method Detail

decode

public String decode(String value)
Decodes a Base64 string into its original form. Escaped characters are converted back to their original representation.

Parameters: value Base64 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.

decode

public Object decode(Object value)
Decodes a Base64 object into its original form. Escaped characters are converted back to their original representation.

Parameters: value Base64 object to convert into its original form

Returns: original object

Throws: DecoderException A decoder exception is thrown if a failure condition is encountered during the decode process.

doDecoding

protected byte[] doDecoding(byte[] bytes)

doEncoding

protected byte[] doEncoding(byte[] bytes)

encode

public String encode(String value, String charset)
Encodes a string into its Base64 form using the specified charset. Unsafe characters are escaped.

Parameters: value string to convert to Base64 form charset the charset for pString

Returns: Base64 string

Throws: EncoderException thrown if a failure condition is encountered during the encoding process.

encode

public String encode(String value)
Encodes a string into its Base64 form using the default charset. Unsafe characters are escaped.

Parameters: value string to convert to Base64 form

Returns: Base64 string

Throws: EncoderException thrown if a failure condition is encountered during the encoding process.

encode

public Object encode(Object value)
Encodes an object into its Base64 form using the default charset. Unsafe characters are escaped.

Parameters: value object to convert to Base64 form

Returns: Base64 object

Throws: EncoderException thrown if a failure condition is encountered during the encoding process.

getDefaultCharset

public String getDefaultCharset()
The default charset used for string decoding and encoding.

Returns: the default string charset.

getEncoding

protected String getEncoding()
commons-codec version 1.3 - Copyright © 2002-2004 - Apache Software Foundation