org.pf.util
Class Base64Converter

java.lang.Object
  extended byorg.pf.util.Base64Converter

public class Base64Converter
extends java.lang.Object

A converter that allows to encode strings, byte arrays and char arrays to BASE64 and vice versa.

Currently it is based on the class Base64 from Robert Harder (http://iharder.sourceforge.net/base64). Thanks to him that he published his implementation as open source. This class mainly adds some convenience methods for string handling.

Version:
1.2
Author:
M.Duchrow

Method Summary
static byte[] decode(char[] encoded)
          Returns a byte array decoded from the given BASE64 encoded char array
static byte[] decode(java.lang.String encoded)
          Returns a byte array decoded from the given BASE64 encoded String
static java.lang.String decodeToString(java.lang.String encoded)
          Returns a string decoded from the given BASE64 encoded String
static java.lang.String decodeToString(java.lang.String encoded, java.lang.String encoding)
          Returns a string decoded from the given BASE64 encoded String
static char[] encode(byte[] unencoded)
          Returns a BASE64 encoded version of the given byte array
static char[] encode(char[] unencoded)
          Returns a BASE64 encoded version of the given character array
static java.lang.String encode(java.lang.String unencoded)
          Returns a BASE64 encoded version of the given string
static java.lang.String encodeToString(byte[] unencoded)
          Returns a BASE64 encoded version of the given byte array as String
static java.lang.String encodeToString(char[] unencoded)
          Returns a BASE64 encoded version of the given char array as String
static java.lang.String encodeToStringWithLineBreaks(byte[] unencoded)
          Returns a BASE64 encoded version of the given byte array as String with a new line (\n) after all 76 bytes (MIME compliant).
static char[] encodeWithLineBreaks(byte[] unencoded)
          Returns a BASE64 encoded version of the given byte array with new lines after all 76 bytes (MIME compliant).
static java.lang.String encodeWithLineBreaks(java.lang.String unencoded)
          Returns a BASE64 encoded version of the given string with new lines after all 76 characters (MIME compliant).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static java.lang.String encode(java.lang.String unencoded)
Returns a BASE64 encoded version of the given string


encodeWithLineBreaks

public static java.lang.String encodeWithLineBreaks(java.lang.String unencoded)
Returns a BASE64 encoded version of the given string with new lines after all 76 characters (MIME compliant).


encode

public static char[] encode(char[] unencoded)
Returns a BASE64 encoded version of the given character array


encode

public static char[] encode(byte[] unencoded)
Returns a BASE64 encoded version of the given byte array


encodeWithLineBreaks

public static char[] encodeWithLineBreaks(byte[] unencoded)
Returns a BASE64 encoded version of the given byte array with new lines after all 76 bytes (MIME compliant).


encodeToString

public static java.lang.String encodeToString(byte[] unencoded)
Returns a BASE64 encoded version of the given byte array as String


encodeToStringWithLineBreaks

public static java.lang.String encodeToStringWithLineBreaks(byte[] unencoded)
Returns a BASE64 encoded version of the given byte array as String with a new line (\n) after all 76 bytes (MIME compliant).


encodeToString

public static java.lang.String encodeToString(char[] unencoded)
Returns a BASE64 encoded version of the given char array as String


decode

public static byte[] decode(char[] encoded)
Returns a byte array decoded from the given BASE64 encoded char array


decode

public static byte[] decode(java.lang.String encoded)
Returns a byte array decoded from the given BASE64 encoded String


decodeToString

public static java.lang.String decodeToString(java.lang.String encoded)
Returns a string decoded from the given BASE64 encoded String

Parameters:
encoded - The BASE64 encoded string

decodeToString

public static java.lang.String decodeToString(java.lang.String encoded,
                                              java.lang.String encoding)
                                       throws java.io.UnsupportedEncodingException
Returns a string decoded from the given BASE64 encoded String

Parameters:
encoded - The BASE64 encoded string
encoding - The name of the reult string's encoding (e.g. "UTF-8").
Throws:
java.io.UnsupportedEncodingException