org.jcoderz.commons.util
Class Base64Util

java.lang.Object
  extended by org.jcoderz.commons.util.Base64Util

public final class Base64Util
extends Object

This class provides encode/decode for RFC 2045 Base64 as defined by RFC 2045, N. Freed and N. Borenstein. RFC 2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. Reference 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt This class is used by XML Schema binary format validation This implementation does not encode/decode streaming data. You need the data that you will encode/decode already on a byte array.

Author:
Michael Griffel TODO: remove deep copy of decoded Base64 data in case of padding chars.

Method Summary
static void appendEncoded(StringBuffer sb, byte[] binaryData)
          Encodes hex octets into Base64.
static byte[] decode(String encoded)
          Decodes Base64 data into octets.
static String encode(byte[] binaryData)
          Encodes hex octets into Base64.
static char[] encodeToChars(byte[] binaryData)
          Encodes hex octets into Base64.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encodeToChars

public static char[] encodeToChars(byte[] binaryData)
Encodes hex octets into Base64.

Parameters:
binaryData - Array containing binary data.
Returns:
Encoded Base64 array

encode

public static String encode(byte[] binaryData)
Encodes hex octets into Base64.

Parameters:
binaryData - Array containing binary data.
Returns:
Encoded Base64 string.

appendEncoded

public static void appendEncoded(StringBuffer sb,
                                 byte[] binaryData)
Encodes hex octets into Base64. The encoded characters are written to the given string buffer sb.

Parameters:
sb - the string buffer that is used to write the Base64 characters to.
binaryData - Array containing binary data.

decode

public static byte[] decode(String encoded)
                     throws ArgumentMalformedException
Decodes Base64 data into octets.

Parameters:
encoded - Base64 encoded string.
Returns:
an array containing decoded data.
Throws:
ArgumentMalformedException - if the given string is not Base64 encoded.


Copyright 2007 The jCoderZ Project.