Artenus 2D Framework
Artenus Reference
Base64 converter class. This code is not a complete MIME encoder; it simply converts binary data to base64 data and back.

Note CharBase64 is a GWT-compatible implementation of this class.

public class Base64

Field Summary

Modifier and TypeField and Description
public static final DECODE
Specify decoding (value is false).
public static final ENCODE
Specify encoding (value is true).

Method Summary

Modifier and TypeMethod and Description
public static bytedecode(String s)
Decodes data from Base64 notation.
public static bytedecode(byte[] source)
Decodes Base64 content in byte array format and returns the decoded byte array.
public static bytedecode(byte[] source, int off, int len)
Decodes Base64 content in byte array format and returns the decoded byte array.
public static bytedecode(byte[] source, int off, int len, byte[] decodabet)
Decodes Base64 content using the supplied decodabet and returns the decoded byte array.
public static bytedecodeWebSafe(String s)
Decodes data from web safe Base64 notation.
public static bytedecodeWebSafe(byte[] source)
Decodes web safe Base64 content in byte array format and returns the decoded data.
public static bytedecodeWebSafe(byte[] source, int off, int len)
Decodes web safe Base64 content in byte array format and returns the decoded byte array.
public static Stringencode(byte[] source)
Encodes a byte array into Base64 notation.
public static Stringencode(byte[] source, int off, int len, byte[] alphabet, boolean doPadding)
Encodes a byte array into Base64 notation.
public static byteencode(byte[] source, int off, int len, byte[] alphabet, int maxLineLength)
Encodes a byte array into Base64 notation.
public static StringencodeWebSafe(byte[] source, boolean doPadding)
Encodes a byte array into web safe Base64 notation.

Methods inherited from java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

DECODE
public static final DECODE
Specify decoding (value is false).
ENCODE
public static final ENCODE
Specify encoding (value is true).

Method Detail

decode
public static byte decode(
    String s
)
Decodes data from Base64 notation.
Parameters:
sthe string to decode (decoded in default encoding)
Returns:
the decoded data
decode
public static byte decode(
    byte[] source
)
Decodes Base64 content in byte array format and returns the decoded byte array.
Parameters:
sourceThe Base64 encoded data
Returns:
decoded data
Throws:
decode
public static byte decode(
    byte[] source,
    int off,
    int len
)
Decodes Base64 content in byte array format and returns the decoded byte array.
Parameters:
sourcethe Base64 encoded data
offthe offset of where to begin decoding
lenthe length of characters to decode
Returns:
decoded data
Throws:
decode
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:
sourcethe Base64 encoded data
offthe offset of where to begin decoding
lenthe length of characters to decode
decodabetthe decodabet for decoding Base64 content
Returns:
decoded data
decodeWebSafe
public static byte decodeWebSafe(
    String s
)
Decodes data from web safe Base64 notation. Web safe encoding uses '-' instead of '+', '_' instead of '/'
Parameters:
sthe string to decode (decoded in default encoding)
Returns:
the decoded data
decodeWebSafe
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:
sourcethe string to decode (decoded in default encoding)
Returns:
the decoded data
decodeWebSafe
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:
sourcethe Base64 encoded data
offthe offset of where to begin decoding
lenthe length of characters to decode
Returns:
decoded data
encode
public static String encode(
    byte[] source
)
Encodes a byte array into Base64 notation. Equivalent to calling encodeBytes(source, 0, source.length)
Parameters:
sourceThe data to convert
encode
public static String encode(
    byte[] source,
    int off,
    int len,
    byte[] alphabet,
    boolean doPadding
)
Encodes a byte array into Base64 notation.
Parameters:
sourcethe data to convert
offoffset in array where conversion should begin
lenlength of data to convert
alphabetthe encoding alphabet
doPaddingis true to pad result with '=' chars if it does not fall on 3 byte boundaries
encode
public static byte encode(
    byte[] source,
    int off,
    int len,
    byte[] alphabet,
    int maxLineLength
)
Encodes a byte array into Base64 notation.
Parameters:
sourcethe data to convert
offoffset in array where conversion should begin
lenlength of data to convert
alphabetis the encoding alphabet
maxLineLengthmaximum length of one line.
Returns:
the BASE64-encoded byte array
encodeWebSafe
public static String encodeWebSafe(
    byte[] source,
    boolean doPadding
)
Encodes a byte array into web safe Base64 notation.
Parameters:
sourceThe data to convert
doPaddingis true to pad result with '=' chars if it does not fall on 3 byte boundaries