com.google.gdata.util.common.util
Class Base64

java.lang.Object
  extended by com.google.gdata.util.common.util.Base64

public class Base64
extends java.lang.Object

Base64 converter class. This code is not a full-blown MIME encoder; it simply converts binary data to base64 data and back.


Field Summary
static byte[] ALPHABET
          The 64 valid Base64 values.
static boolean DECODE
          Specify decoding (value is false).
static boolean ENCODE
          Specify encoding (value is true).
static byte[] WEBSAFE_ALPHABET
          The 64 valid web safe Base64 values.
 
Method Summary
static byte[] decode(byte[] source)
          Decodes Base64 content in byte array format and returns the decoded byte array.
static byte[] decode(byte[] source, int off, int len)
          Decodes Base64 content in byte array format and returns the decoded byte array.
static byte[] decode(byte[] source, int off, int len, byte[] decodabet)
          Decodes Base64 content using the supplied decodabet and returns the decoded byte array.
static byte[] decode(java.lang.String s)
          Decodes data from Base64 notation.
static byte[] decodeWebSafe(byte[] source)
          Decodes web safe Base64 content in byte array format and returns the decoded data.
static byte[] decodeWebSafe(byte[] source, int off, int len)
          Decodes web safe Base64 content in byte array format and returns the decoded byte array.
static byte[] decodeWebSafe(java.lang.String s)
          Decodes data from web safe Base64 notation.
static java.lang.String encode(byte[] source)
          Encodes a byte array into Base64 notation.
static java.lang.String encode(byte[] source, int off, int len, byte[] alphabet, boolean doPadding)
          Encodes a byte array into Base64 notation.
static byte[] encode(byte[] source, int off, int len, byte[] alphabet, int maxLineLength)
          Encodes a byte array into Base64 notation.
static java.lang.String encodeWebSafe(byte[] source, boolean doPadding)
          Encodes a byte array into web safe Base64 notation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODE

public static final boolean ENCODE
Specify encoding (value is true).

See Also:
Constant Field Values

DECODE

public static final boolean DECODE
Specify decoding (value is false).

See Also:
Constant Field Values

ALPHABET

public static final byte[] ALPHABET
The 64 valid Base64 values. made private and a method that returns a clone can be added.


WEBSAFE_ALPHABET

public static final byte[] WEBSAFE_ALPHABET
The 64 valid web safe Base64 values. made private and a method that returns a clone can be added.

Method Detail

encode

public static java.lang.String encode(byte[] source)
Encodes a byte array into Base64 notation. Equivalent to calling encodeBytes(source, 0, source.length)

Parameters:
source - The data to convert
Since:
1.4

encodeWebSafe

public static java.lang.String encodeWebSafe(byte[] source,
                                             boolean doPadding)
Encodes a byte array into web safe Base64 notation.

Parameters:
source - The data to convert
doPadding - is true to pad result with '=' chars if it does not fall on 3 byte boundaries

encode

public static java.lang.String encode(byte[] source,
                                      int off,
                                      int len,
                                      byte[] alphabet,
                                      boolean doPadding)
Encodes a byte array into Base64 notation.

Parameters:
source - The data to convert
off - Offset in array where conversion should begin
len - Length of data to convert
alphabet - is the encoding alphabet
doPadding - is true to pad result with '=' chars if it does not fall on 3 byte boundaries
Since:
1.4

encode

public static byte[] encode(byte[] source,
                            int off,
                            int len,
                            byte[] alphabet,
                            int maxLineLength)
Encodes a byte array into Base64 notation.

Parameters:
source - The data to convert
off - Offset in array where conversion should begin
len - Length of data to convert
alphabet - is the encoding alphabet
maxLineLength - maximum length of one line.
Returns:
the BASE64-encoded byte array

decode

public static byte[] decode(java.lang.String s)
                     throws Base64DecoderException
Decodes data from Base64 notation.

Parameters:
s - the string to decode (decoded in default encoding)
Returns:
the decoded data
Throws:
Base64DecoderException
Since:
1.4

decodeWebSafe

public static byte[] decodeWebSafe(java.lang.String s)
                            throws Base64DecoderException
Decodes data from web safe Base64 notation. Web safe encoding uses '-' instead of '+', '_' instead of '/'

Parameters:
s - the string to decode (decoded in default encoding)
Returns:
the decoded data
Throws:
Base64DecoderException

decode

public static byte[] decode(byte[] source)
                     throws Base64DecoderException
Decodes Base64 content in byte array format and returns the decoded byte array.

Parameters:
source - The Base64 encoded data
Returns:
decoded data
Throws:
Base64DecoderException
Since:
1.3

decodeWebSafe

public static byte[] decodeWebSafe(byte[] source)
                            throws Base64DecoderException
Decodes web safe Base64 content in byte array format and returns the decoded data. Web safe encoding uses '-' instead of '+', '_' instead of '/'

Parameters:
source - the string to decode (decoded in default encoding)
Returns:
the decoded data
Throws:
Base64DecoderException

decode

public static byte[] decode(byte[] source,
                            int off,
                            int len)
                     throws Base64DecoderException
Decodes Base64 content in byte array format and returns the decoded byte array.

Parameters:
source - The Base64 encoded data
off - The offset of where to begin decoding
len - The length of characters to decode
Returns:
decoded data
Throws:
Base64DecoderException
Since:
1.3

decodeWebSafe

public static byte[] decodeWebSafe(byte[] source,
                                   int off,
                                   int len)
                            throws Base64DecoderException
Decodes web safe Base64 content in byte array format and returns the decoded byte array. Web safe encoding uses '-' instead of '+', '_' instead of '/'

Parameters:
source - The Base64 encoded data
off - The offset of where to begin decoding
len - The length of characters to decode
Returns:
decoded data
Throws:
Base64DecoderException

decode

public static byte[] decode(byte[] source,
                            int off,
                            int len,
                            byte[] decodabet)
                     throws Base64DecoderException
Decodes Base64 content using the supplied decodabet and returns the decoded byte array.

Parameters:
source - The Base64 encoded data
off - The offset of where to begin decoding
len - The length of characters to decode
decodabet - the decodabet for decoding Base64 content
Returns:
decoded data
Throws:
Base64DecoderException