FileDocCategorySizeDatePackage
BCodec.javaAPI DocAndroid 1.5 API6803Wed May 06 22:41:10 BST 2009org.apache.commons.codec.net

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.

see
MIME (Multipurpose Internet Mail Extensions) Part Two: Message Header Extensions for Non-ASCII Text
author
Apache Software Foundation
since
1.3
version
$Id: BCodec.java,v 1.5 2004/04/13 22:46:37 ggregory Exp $

Fields Summary
private String
charset
The default charset used for string decoding and encoding.
Constructors Summary
public BCodec()
Default constructor.


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

param
charset the default string charset to use.
see
JRE character encoding names

        super();
        this.charset = charset;
    
Methods Summary
public java.lang.Objectdecode(java.lang.Object value)
Decodes a Base64 object into its original form. Escaped characters are converted back to their original representation.

param
value Base64 object to convert into its original form
return
original object
throws
DecoderException A decoder exception is thrown if a failure condition is encountered during the decode process.

        if (value == null) {
            return null;
        } else if (value instanceof String) {
            return decode((String) value);
        } else {
            throw new DecoderException("Objects of type "
                + value.getClass().getName()
                + " cannot be decoded using BCodec");
        }
    
public java.lang.Stringdecode(java.lang.String value)
Decodes a Base64 string into its original form. Escaped characters are converted back to their original representation.

param
value Base64 string to convert into its original form
return
original string
throws
DecoderException A decoder exception is thrown if a failure condition is encountered during the decode process.

        if (value == null) {
            return null;
        }
        try {
            return decodeText(value);
        } catch (UnsupportedEncodingException e) {
            throw new DecoderException(e.getMessage());
        }
    
protected byte[]doDecoding(byte[] bytes)

        if (bytes == null) {
            return null;
        }
        return Base64.decodeBase64(bytes);
    
protected byte[]doEncoding(byte[] bytes)

        if (bytes == null) {
            return null;
        }
        return Base64.encodeBase64(bytes);
    
public java.lang.Stringencode(java.lang.String value, java.lang.String charset)
Encodes a string into its Base64 form using the specified charset. Unsafe characters are escaped.

param
value string to convert to Base64 form
param
charset the charset for pString
return
Base64 string
throws
EncoderException thrown if a failure condition is encountered during the encoding process.

        if (value == null) {
            return null;
        }
        try {
            return encodeText(value, charset);
        } catch (UnsupportedEncodingException e) {
            throw new EncoderException(e.getMessage());
        }
    
public java.lang.Stringencode(java.lang.String value)
Encodes a string into its Base64 form using the default charset. Unsafe characters are escaped.

param
value string to convert to Base64 form
return
Base64 string
throws
EncoderException thrown if a failure condition is encountered during the encoding process.

        if (value == null) {
            return null;
        }
        return encode(value, getDefaultCharset());
    
public java.lang.Objectencode(java.lang.Object value)
Encodes an object into its Base64 form using the default charset. Unsafe characters are escaped.

param
value object to convert to Base64 form
return
Base64 object
throws
EncoderException thrown if a failure condition is encountered during the encoding process.

        if (value == null) {
            return null;
        } else if (value instanceof String) {
            return encode((String) value);
        } else {
            throw new EncoderException("Objects of type "
                + value.getClass().getName()
                + " cannot be encoded using BCodec");
        }
    
public java.lang.StringgetDefaultCharset()
The default charset used for string decoding and encoding.

return
the default string charset.

        return this.charset;
    
protected java.lang.StringgetEncoding()

        return "B";