org.PingOO.DLAI.lib.util
Class Base64Codec

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.util.Base64Codec

public final class Base64Codec
extends java.lang.Object

Provides encoding of raw bytes to base64-encoded characters, and decoding of base64 characters to raw bytes.

Since:
PingOO 2.0
Version:
1.0
Author:
Kevin Kelley (kelley@iguana.ruralnet.net), Fabrice Bouyé (bouye@cur-archamps.fr)

Field Summary
private static char[] alphabet
          Code characters for values 0..63
private static byte[] codes
          lookup table for converting base64 characters to value in range 0..63
 
Constructor Summary
private Base64Codec()
          Hides the constructor from the outside.
 
Method Summary
static byte[] decode(char[] data)
          Returns an array of bytes which were encoded in the passed character array.
static byte[] decode(java.lang.String data)
          Returns an array of bytes which were encoded in the passed String.
static char[] encode(byte[] data)
          Returns an array of base64-encoded characters to represent the passed data array.
static char[] encode(char[] data)
          Returns an array of base64-encoded characters to represent the passed data array.
static char[] encode(java.lang.String data)
          Returns an array of base64-encoded characters to represent the passed data String.
private static void generateAlphabet()
          Generates the base64 alphabet.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

alphabet

private static final char[] alphabet
Code characters for values 0..63

codes

private static byte[] codes
lookup table for converting base64 characters to value in range 0..63
Constructor Detail

Base64Codec

private Base64Codec()
Hides the constructor from the outside.
Method Detail

generateAlphabet

private static final void generateAlphabet()
Generates the base64 alphabet.

encode

public static final char[] encode(byte[] data)
                           throws java.lang.NullPointerException
Returns an array of base64-encoded characters to represent the passed data array.
Parameters:
data - The array of bytes to encode.
Returns:
Base64-coded character array.
Throws:
java.lang.NullPointerException - If data is null.

encode

public static final char[] encode(char[] data)
                           throws java.lang.NullPointerException
Returns an array of base64-encoded characters to represent the passed data array.
Parameters:
data - The array of char to encode.
Returns:
Base64-coded character array.
Throws:
java.lang.NullPointerException - If data is null.

encode

public static final char[] encode(java.lang.String data)
                           throws java.lang.NullPointerException
Returns an array of base64-encoded characters to represent the passed data String.
This is a convenient way to avoid a call to the toCharArray() method.
Parameters:
data - The String to encode.
Returns:
Base64-coded character array.
Throws:
java.lang.NullPointerException - If data is null.

decode

public static final byte[] decode(char[] data)
                           throws java.lang.NullPointerException
Returns an array of bytes which were encoded in the passed character array.
Parameters:
data - The array of base64-encoded characters.
Returns:
Decoded data array.
Throws:
java.lang.NullPointerException - If data is null.

decode

public static final byte[] decode(java.lang.String data)
                           throws java.lang.NullPointerException
Returns an array of bytes which were encoded in the passed String.
This is convenient way to avoid a to call to the toCharArray() method.
Parameters:
data - The array of base64-encoded characters.
Returns:
Decoded data array.
Throws:
java.lang.NullPointerException - If data is null.