jfileupload.transfer.client.util
Class Base64

java.lang.Object
  extended by jfileupload.transfer.client.util.Base64

public class Base64
extends java.lang.Object

Base64 encoder/decoder.


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.
 
Constructor Summary
Base64()
          Base64 decoder.
 
Method Summary
 java.lang.String bytesToCharString(byte[] retData)
          Returns a String matching to the byte array.
 java.lang.String decode(java.lang.String msg)
          Return Base64 decoded String.
 byte[] decodeBase64(byte[] data)
          Decodes a byte array containing base64-encoded ASCII.
 int decodeBase64(byte[] ret, int ret_off, byte a, byte b, byte c, byte d)
          Given a block of 4 encoded bytes { a, b, c, d }, this method decodes up to 3 bytes of output, and stores them starting at ret[ret_offset].
 byte[] decodeBase64(java.lang.String msg)
          Decodes a base64-encoded String.
 byte[] encodeAsByteArray(byte[] data)
          Encodes data as a byte array using base64 encoding.
 java.lang.String encodeBase64(byte[] data)
          Encodes data as a String using base64 encoding.
 java.lang.String encodeBase64(java.lang.String data)
          Encode base64 string.
 
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.

Constructor Detail

Base64

public Base64()
Base64 decoder.

Method Detail

decodeBase64

public byte[] decodeBase64(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.

decodeBase64

public byte[] decodeBase64(java.lang.String msg)
                    throws java.lang.IllegalArgumentException
Decodes a base64-encoded String. Characters with ASCII code points <= 32 (this includes whitespace and newlines) are ignored.

Returns:
the decoded data.
Throws:
java.lang.IllegalArgumentException

decode

public java.lang.String decode(java.lang.String msg)
                        throws java.lang.IllegalArgumentException
Return Base64 decoded String.

Parameters:
msg -
Returns:
Throws:
java.lang.IllegalArgumentException

decodeBase64

public int decodeBase64(byte[] ret,
                        int ret_off,
                        byte a,
                        byte b,
                        byte c,
                        byte d)
Given a block of 4 encoded bytes { a, b, c, d }, this method decodes up to 3 bytes of output, and stores them starting at ret[ret_offset].

Returns:
the number of bytes converted.

encodeBase64

public java.lang.String encodeBase64(java.lang.String data)
Encode base64 string.

Parameters:
data -
Returns:

encodeBase64

public java.lang.String encodeBase64(byte[] data)
Encodes data as a String using base64 encoding. Line breaks in the output are represented as CR LF.

Returns:
the encoded string.

bytesToCharString

public java.lang.String bytesToCharString(byte[] retData)
Returns a String matching to the byte array.


encodeAsByteArray

public byte[] encodeAsByteArray(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.