net.wimpi.pim.util
Class Base64

java.lang.Object
  |
  +--net.wimpi.pim.util.Base64

public class Base64
extends java.lang.Object

This class provides methods for encoding and decoding data in MIME base64 format.

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.8 Base64 Content-Transfer-Encoding," http://www.imc.org/rfc2045

Version:
Distributed with 0.1 (22/07/2003)
Author:
Jill Baker, David Hopwood

Field Summary
protected static byte[] dec_table
          A static array that maps ASCII code points to a 6-bit integer, or -1 for an invalid code point.
protected static char[] enc_table
          A static array that maps 6-bit integers to a specific char.
 
Method Summary
static byte[] decode(byte[] data)
          Decodes a byte array containing base64-encoded ASCII.
static byte[] encode(byte[] data)
          Encodes data as a byte array using base64 encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enc_table

protected static final char[] enc_table
A static array that maps 6-bit integers to a specific char.


dec_table

protected static final byte[] dec_table
A static array that maps ASCII code points to a 6-bit integer, or -1 for an invalid code point.

Method Detail

encode

public static final byte[] encode(byte[] data)
Encodes data as a byte array using base64 encoding. The characters 'A'-'Z', 'a'-'z', '0'-'9', '+', '/', and '=' in the output are mapped to their ASCII code points. Line breaks in the output are represented as CR LF (codes 13 and 10).

Returns:
the encoded byte array.

decode

public static final byte[] decode(byte[] data)
Decodes a byte array containing base64-encoded ASCII. Characters with ASCII code points <= 32 (this includes whitespace and newlines) are ignored.

Returns:
the decoded data.
Throws:
java.lang.IllegalArgumentException - if data contains invalid characters, i.e. not codes 0-32, 'A'-'Z', 'a'-'z', '+', '/'. or '=', or is incorrectly padded.


Copyright © 2001-2003 jpim team.