unsw.cse.mica.util
Class Base64

java.lang.Object
  extended by unsw.cse.mica.util.Base64

public class Base64
extends java.lang.Object

This class provides methods for encoding and decoding binary data into base64 notation so it can be embedded in mobs.

Author:
mmcgill

Nested Class Summary
static class Base64.CorruptedDataException
          An exception that is thrown when base64 data is decoded and it is found to be corrupted.
 
Constructor Summary
Base64()
           
 
Method Summary
static byte[] decode(char[] data)
          Decodes a sequence of characters in base64 notation into binary data.
static byte[] decode(char[] data, int offset, int len)
          Decodes a sequence of characters in base64 notation into binary data.
static char[] encode(byte[] data)
          Encodes binary data into a sequences of characters.
static char[] encode(byte[] data, int offset, int len)
          Encodes binary data into a sequences of characters.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Base64

public Base64()
Method Detail

encode

public static char[] encode(byte[] data)
Encodes binary data into a sequences of characters. The returned array will include padding to ensure the size is a multiple of 4.

Parameters:
data - the data to be encoded
Returns:
the data encoded as an array of characters

encode

public static char[] encode(byte[] data,
                            int offset,
                            int len)
Encodes binary data into a sequences of characters. The returned array will include padding to ensure the size is a multiple of 4.

Parameters:
data - the data to be encoded
offset - starting point of the data to be encoded
len - the number of bytes of data to be encoded
Returns:
the data encoded as an array of characters

decode

public static byte[] decode(char[] data)
                     throws Base64.CorruptedDataException
Decodes a sequence of characters in base64 notation into binary data. The given data may or may not include padding to ensure its length is a multiple of 4.

Parameters:
data - the sequence of characters to be decoded
Returns:
the decoded binary data
Throws:
Base64.CorruptedDataException - if the sequence of characters in array are not base64

decode

public static byte[] decode(char[] data,
                            int offset,
                            int len)
                     throws Base64.CorruptedDataException
Decodes a sequence of characters in base64 notation into binary data. The given data may or may not include padding to ensure its length is a multiple of 4.

Parameters:
data - the sequence of characters to be decoded
offset - starting point of the data to be decoded
len - the number of bytes of data to be decoded
Returns:
the decoded binary data
Throws:
Base64.CorruptedDataException - if the sequence of characters in array are not base64