org.springframework.webflow.util
Class Base64

java.lang.Object
  extended by org.springframework.webflow.util.Base64

public class Base64
extends java.lang.Object

Encodes and decodes to and from Base64 notation.

Based on Base64 encoder and decoder version 2.2.1 written by Robert Harder (http://iharder.net/base64). Modified by Erwin Vervaet to use the '.' character as padding character when using URL safe encoding, like in the Bouncy Castle URLBase64 encoder (http://www.bouncycastle.org/java.html).

Author:
Robert Harder, Erwin Vervaet

Constructor Summary
Base64()
          Create a new Base64 encoder and decoder using the standard Base64 alphabet.
Base64(boolean urlSafe)
          Create a new Base64 encoder and decoder.
 
Method Summary
 byte[] decode(byte[] source)
          Decodes data from Base64 notation.
 byte[] decode(byte[] source, int off, int len)
          Very low-level access to decoding ASCII characters in the form of a byte array.
 byte[] decodeFromString(java.lang.String s)
          Decodes data from Base64 notation.
 byte[] encode(byte[] source)
          Encodes a byte array into Base64 notation.
 byte[] encode(byte[] source, int off, int len)
          Encodes a byte array into Base64 notation.
 java.lang.String encodeToString(byte[] source)
          Encodes a byte array into Base64 notation.
 boolean isUrlSafe()
          Returns whether or not this coder is using Base64-like encoding that is URL- and Filename-safe as described in Section 4 of RFC3548: http://www.faqs.org/rfcs/rfc3548.html.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Base64

public Base64()
Create a new Base64 encoder and decoder using the standard Base64 alphabet. Note that the resulting encoded strings are not URL-safe: they will can contain characters that are subject to URL encoding.


Base64

public Base64(boolean urlSafe)
Create a new Base64 encoder and decoder.

Allows Base64-like encoding that is URL- and Filename-safe as described in Section 4 of RFC3548: http://www.faqs.org/rfcs/rfc3548.html. When URL-safe encoding is used, the standard "=" Base64 padding character is replaced with the '.' character.

It is important to note that data encoded this way is not officially valid Base64, or at the very least should not be called Base64 without also specifying that is was encoded using the URL- and Filename-safe dialect

Parameters:
urlSafe - if true, URL safe encoding and decoding will be used
Method Detail

isUrlSafe

public boolean isUrlSafe()
Returns whether or not this coder is using Base64-like encoding that is URL- and Filename-safe as described in Section 4 of RFC3548: http://www.faqs.org/rfcs/rfc3548.html. When URL-safe encoding is used, the standard "=" Base64 padding character is replaced with the '.' character.

It is important to note that data encoded this way is not officially valid Base64, or at the very least should not be called Base64 without also specifying that is was encoded using the URL- and Filename-safe dialect.

Returns:
true or false

encode

public final byte[] encode(byte[] source,
                           int off,
                           int len)
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
Returns:
the encoded data

encode

public final byte[] encode(byte[] source)
Encodes a byte array into Base64 notation.

Parameters:
source - the data to encode
Returns:
the encoded data

encodeToString

public final java.lang.String encodeToString(byte[] source)
Encodes a byte array into Base64 notation. The resulting string will be created using the platform default encoding.

Parameters:
source - the source data to encode
Returns:
the encoded data

decode

public final byte[] decode(byte[] source,
                           int off,
                           int len)
Very low-level access to decoding ASCII characters in the form of a 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

decode

public final byte[] decode(byte[] source)
Decodes data from Base64 notation.

Parameters:
source - the source data
Returns:
the decoded data

decodeFromString

public final byte[] decodeFromString(java.lang.String s)
Decodes data from Base64 notation. Uses the platform default character set to obtain bytes from given string.

Parameters:
s - the string to decode
Returns:
the decoded data


Copyright © 2004-2007. All Rights Reserved.