org.apache.commons.codec.binary
Class Base64

java.lang.Object
  |
  +--org.apache.commons.codec.binary.Base64
All Implemented Interfaces:
BinaryDecoder, BinaryEncoder, Decoder, Encoder

public class Base64
extends java.lang.Object
implements BinaryEncoder, BinaryDecoder

This class provides encode/decode for RFC 2045 Base64 as defined by RFC 2045, N. Freed and N. Borenstein. RFC 2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. Reference 1996

Since:
1.0-dev
Author:
Jeffrey Rodriguez, Daniel Rall, Martin Redington

Field Summary
private static byte[] base64Alphabet
           
(package private) static int BASELENGTH
           
(package private) static byte[] CHUNK_SEPARATOR
           
(package private) static int CHUNK_SIZE
           
(package private) static int EIGHTBIT
           
(package private) static int FOURBYTE
           
private static byte[] lookUpBase64Alphabet
           
(package private) static int LOOKUPLENGTH
           
(package private) static byte PAD
           
(package private) static int SIGN
           
(package private) static int SIXBIT
           
(package private) static int SIXTEENBIT
           
(package private) static int TWENTYFOURBITGROUP
           
 
Constructor Summary
Base64()
           
 
Method Summary
 byte[] decode(byte[] pArray)
          Decode a byte array and return the results of the decode as a byte array.
 java.lang.Object decode(java.lang.Object pObject)
          Decode an "encoded" Object and return a "decoded" Object.
static byte[] decodeBase64(byte[] base64Data)
          Decodes Base64 data into octects
(package private) static byte[] discardWhitespace(byte[] data)
          Discards any whitespace from a base-64 encoded block.
 byte[] encode(byte[] pArray)
          Encode a byte array and return the encoded data as a byte array.
 java.lang.Object encode(java.lang.Object pObject)
          encode an Object
static byte[] encodeBase64(byte[] binaryData)
           
static byte[] encodeBase64(byte[] binaryData, boolean isChunked)
          Encodes hex octects into Base64.
static byte[] encodeBase64Chunked(byte[] binaryData)
           
static boolean isArrayByteBase64(byte[] arrayOctect)
           
private static boolean isBase64(byte octect)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHUNK_SIZE

static final int CHUNK_SIZE
See Also:
Constant Field Values

CHUNK_SEPARATOR

static final byte[] CHUNK_SEPARATOR

BASELENGTH

static final int BASELENGTH
See Also:
Constant Field Values

LOOKUPLENGTH

static final int LOOKUPLENGTH
See Also:
Constant Field Values

TWENTYFOURBITGROUP

static final int TWENTYFOURBITGROUP
See Also:
Constant Field Values

EIGHTBIT

static final int EIGHTBIT
See Also:
Constant Field Values

SIXTEENBIT

static final int SIXTEENBIT
See Also:
Constant Field Values

SIXBIT

static final int SIXBIT
See Also:
Constant Field Values

FOURBYTE

static final int FOURBYTE
See Also:
Constant Field Values

SIGN

static final int SIGN
See Also:
Constant Field Values

PAD

static final byte PAD
See Also:
Constant Field Values

base64Alphabet

private static byte[] base64Alphabet

lookUpBase64Alphabet

private static byte[] lookUpBase64Alphabet
Constructor Detail

Base64

public Base64()
Method Detail

isBase64

private static boolean isBase64(byte octect)

isArrayByteBase64

public static boolean isArrayByteBase64(byte[] arrayOctect)

encodeBase64

public static byte[] encodeBase64(byte[] binaryData)

encodeBase64Chunked

public static byte[] encodeBase64Chunked(byte[] binaryData)

decode

public java.lang.Object decode(java.lang.Object pObject)
                        throws DecoderException
Description copied from interface: Decoder
Decode an "encoded" Object and return a "decoded" Object. Note that the implementation of this interface will try to cast the Object parameter to the specific type expected by a particular Decoder implementation. If a ClassCastException occurs this decode method will throw a DecoderException.

Specified by:
decode in interface Decoder
Parameters:
pObject - an object to "decode"
Returns:
a 'decoded" object
Throws:
DecoderException - a decoder exception can be thrown for any number of reasons. Some good candidates are that the parameter passed to this method is null, a param cannot be cast to the appropriate type for a specific encoder.

decode

public byte[] decode(byte[] pArray)
              throws DecoderException
Description copied from interface: BinaryDecoder
Decode a byte array and return the results of the decode as a byte array.

Specified by:
decode in interface BinaryDecoder
Parameters:
pArray - A byte array which has been encoded with the appropriate encoder
Returns:
a byte array that contains decoded content
Throws:
DecoderException - A decoder exception is thrown if a Decoder encounters a failure condition during the decode process.

encodeBase64

public static byte[] encodeBase64(byte[] binaryData,
                                  boolean isChunked)
Encodes hex octects into Base64.

Parameters:
binaryData - Array containing binary data to encode.
Returns:
Base64-encoded data.

decodeBase64

public static byte[] decodeBase64(byte[] base64Data)
Decodes Base64 data into octects

Returns:
Array containing decoded data.

discardWhitespace

static byte[] discardWhitespace(byte[] data)
Discards any whitespace from a base-64 encoded block.

Parameters:
data - The base-64 encoded data to discard the whitespace from.
Returns:
The data, less whitespace (see RFC 2045).

encode

public java.lang.Object encode(java.lang.Object pObject)
                        throws EncoderException
encode an Object

Specified by:
encode in interface Encoder
Parameters:
pObject - An object ot encode
Returns:
An "encoded" Object
Throws:
EncoderException - an encoder exception is thrown if the encoder experiences a failure condition during the encoding process.

encode

public byte[] encode(byte[] pArray)
              throws EncoderException
Description copied from interface: BinaryEncoder
Encode a byte array and return the encoded data as a byte array.

Specified by:
encode in interface BinaryEncoder
Parameters:
pArray - Data to be encoded
Returns:
A byte array containing the encoded data
Throws:
EncoderException - thrown if the Encoder encounters a failure condition during the encoding process.


Copyright (c) 2003 - Apache Software Foundation