public class

Base64

extends Object
java.lang.Object
   ↳ com.google.gdata.util.common.util.Base64

Class Overview

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

Summary

Constants
boolean DECODE Specify decoding (value is false).
boolean ENCODE Specify encoding (value is true).
byte EQUALS_SIGN The equals sign (=) as a byte.
byte EQUALS_SIGN_ENC
byte NEW_LINE The new line character (\n) as a byte.
byte WHITE_SPACE_ENC
Fields
public static final byte[] ALPHABET The 64 valid Base64 values.
private static final byte[] DECODABET Translates a Base64 value to either its 6-bit reconstruction value or a negative number indicating some other meaning.
public static final byte[] WEBSAFE_ALPHABET The 64 valid web safe Base64 values.
private static final byte[] WEBSAFE_DECODABET The web safe decodabet
Public Methods
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, byte[] decodabet)
Decodes Base64 content using the supplied decodabet and returns the decoded byte array.
static byte[] decode(String s)
Decodes data from Base64 notation.
static byte[] decode(byte[] source, int off, int len)
Decodes Base64 content in byte array format and returns the decoded byte array.
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(String s)
Decodes data from web safe Base64 notation.
static byte[] decodeWebSafe(byte[] source)
Decodes web safe Base64 content in byte array format and returns the decoded data.
static String encode(byte[] source, int off, int len, byte[] alphabet, boolean doPadding)
Encodes a byte array into Base64 notation.
static String encode(byte[] source)
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 String encodeWebSafe(byte[] source, boolean doPadding)
Encodes a byte array into web safe Base64 notation.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final boolean DECODE

Specify decoding (value is false).

Constant Value: false

public static final boolean ENCODE

Specify encoding (value is true).

Constant Value: true

private static final byte EQUALS_SIGN

The equals sign (=) as a byte.

Constant Value: 61 (0x0000003d)

private static final byte EQUALS_SIGN_ENC

Constant Value: -1 (0xffffffff)

private static final byte NEW_LINE

The new line character (\n) as a byte.

Constant Value: 10 (0x0000000a)

private static final byte WHITE_SPACE_ENC

Constant Value: -5 (0xfffffffb)

Fields

public static final byte[] ALPHABET

The 64 valid Base64 values. made private and a method that returns a clone can be added.

private static final byte[] DECODABET

Translates a Base64 value to either its 6-bit reconstruction value or a negative number indicating some other meaning.

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.

private static final byte[] WEBSAFE_DECODABET

The web safe decodabet

Public Methods

public static byte[] decode (byte[] source)

Decodes Base64 content in byte array format and returns the decoded byte array.

Parameters
source The Base64 encoded data
Returns
  • decoded data

public static byte[] decode (byte[] source, int off, int len, byte[] decodabet)

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

public static byte[] decode (String s)

Decodes data from Base64 notation.

Parameters
s The string to decode (decoded in default encoding)
Returns
  • the decoded data

public static byte[] decode (byte[] source, int off, int len)

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

public static byte[] decodeWebSafe (byte[] source, int off, int len)

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

public static byte[] decodeWebSafe (String s)

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

public static byte[] decodeWebSafe (byte[] source)

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

public static 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

public static 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

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

public static 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