ahc.util.string
Class Base64Formatter

java.lang.Object
  |
  +--ahc.util.string.Base64Formatter

public class Base64Formatter
extends java.lang.Object

This class provides methods for encoding arbitrary data (i.e. byte arrays) in Base64, a standardized format using only "printable" characters.

Author:
Arno Haase

Constructor Summary
Base64Formatter()
           
 
Method Summary
static byte[] decode(byte[] data)
          This method decodes a sequence of bytes from Base64 encoding into the original byte sequence.
static byte[] decode(java.lang.String str)
          This method decodes a sequence of bytes from Base64 encoding into the original byte sequence.
static byte[] encode(byte[] data)
          encodes the given data and returns the result in string form.
static java.lang.String encodeToString(byte[] data)
          encodes the given data and returns the result in string form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Base64Formatter

public Base64Formatter()
Method Detail

encodeToString

public static java.lang.String encodeToString(byte[] data)
encodes the given data and returns the result in string form.

Passing in null return null.

Strictly speaking, the result of the encoding process is a byte array (or rather, a sequence of ASCII characters, which is basically the same) and not a string so that the string representation would depend on the encoding used. But given the nature of Base64, the string representation of the characters used is widely independent of the encoding used as long as it is a single-byte encoding. Specifically, ASCII, ISO-8859-1 and UTF-8 all yield the same results.


encode

public static byte[] encode(byte[] data)
encodes the given data and returns the result in string form.

Passing in null return null.


decode

public static final byte[] decode(java.lang.String str)
This method decodes a sequence of bytes from Base64 encoding into the original byte sequence.

Passing in null returns null.

Strictly speaking, the result of the encoding process is a byte array (or rather, a sequence of ASCII characters, which is basically the same) and not a string so that the string representation would depend on the encoding used. But given the nature of Base64, the string representation of the characters used is widely independent of the encoding used as long as it is a single-byte encoding. Specifically, ASCII, ISO-8859-1 and UTF-8 all yield the same results.


decode

public static final byte[] decode(byte[] data)
This method decodes a sequence of bytes from Base64 encoding into the original byte sequence.

Passing in null returns null.