codec
Class Base64

java.lang.Object
  |
  +--codec.Base64

public final class Base64
extends Object

Encodes and decodes data according to Base64 encoding as described in RFC 1521. Encoded data is broken into lines of 76 charcters each (19 groups of 4 characters which represent 3 bytes of input per group.

The three input bytes are divided into four groups of six bits each which are encoded according to the table base64 given below.

Version:
"$Id: Base64.java,v 1.5 2005/04/06 09:23:31 flautens Exp $"
Author:
Volker Roth

Method Summary
static byte[] decode(byte[] code)
          Decodes a given byte array containing Unicode BASE_LATIN encoded characters with one byte encoding per character.
static byte[] decode(String input)
          Decodes a Base64 encoded string into an array of bytes with exactly the length of the encoded data.
static String encode(byte[] input)
          Encodes the input array of bytes into a Base64 encoded string with padding if required.
static String toHex(byte[] b)
          Encodes a byte array into a hexadecimal string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static String encode(byte[] input)
Encodes the input array of bytes into a Base64 encoded string with padding if required. The output is not broken into lines.
Parameters:
input - The byte array to be encoded.
Returns:
The Base64 encoded String representing the input byte array.

decode

public static byte[] decode(String input)
                     throws CorruptedCodeException
Decodes a Base64 encoded string into an array of bytes with exactly the length of the encoded data. The encoded string may contain arbitrarily much garbage data in the form of control sequences and non-base64 characters as long as the local charcter encoding is Unicode BASE_LATIN.

Parameters:
input - The encoded Base64 character String.
Returns:
The decoded data.
Throws:
CorruptedCodeException - if the Base64 code contains errors such as a missing character or bad padding.

decode

public static byte[] decode(byte[] code)
                     throws CorruptedCodeException
Decodes a given byte array containing Unicode BASE_LATIN encoded characters with one byte encoding per character. The array is garbled in the course of the decoding, because it is partly overwritten with the six Bit groups represented by the code letters! This method is used by the decoding method byte[] decode(String).
Parameters:
code - The BASE_LATIN Base64 encoded input with one byte per character.
Returns:
The byte array containing the decoded data. The array has the exact length of the decoded data.
Throws:
CorruptedCodeException - if the decoding process revealed errors such as bad padding or missing charcters.

toHex

public static String toHex(byte[] b)
Encodes a byte array into a hexadecimal string representation.
Parameters:
b - The input byte array.
Returns:
The string with the hexadecimal representation.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.