QJCC homepage

biz.chitec.quarterback.util
Class Base64

java.lang.Object
  extended bybiz.chitec.quarterback.util.Base64

public final class Base64
extends java.lang.Object

Base64 codec.

Version:
$Id: 7a5d7df4c4c4f60b9a4606e80f15ad31dd6e8b64 $
Author:
Dirk Hillbrecht 1997-1999, chitec/Dirk Hillbrecht 2000,2002. Distributed under the terms of the GNU LGPL.

Field Summary
private static java.lang.String base64
          The characters for base64 encoded strings
private static java.lang.String hex16
          The characters for hex encoded strings
private static byte pad
          The pad character for the final chunk
 
Constructor Summary
private Base64()
          Constructor for the Base64 object
 
Method Summary
private static int decodeChunk(byte[] input, byte[] output)
          Decode 4 bytes of printable ASCII text into up to 3 bytes of binary data.
private static byte[] encodeChunk(byte[] input, int len)
          Encode up to 3 bytes of binary data as 4 bytes of printable ASCII text.
static java.lang.String toBase64(byte[] bin)
          Converts an array of binary data into a String in Base64 encoding.
static byte[] toBinary(java.lang.String toconv)
          Converty a String in Base64 encoding into binary data.
static int toBinary(java.lang.String toconv, byte[] target)
          Convert a String in Base64 encoding into binary data in the given array.
static java.lang.String toHex16(byte[] bin)
          Converts an array of binary data into a String in Hex16 encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base64

private static final java.lang.String base64
The characters for base64 encoded strings

See Also:
Constant Field Values

pad

private static final byte pad
The pad character for the final chunk

See Also:
Constant Field Values

hex16

private static final java.lang.String hex16
The characters for hex encoded strings

See Also:
Constant Field Values
Constructor Detail

Base64

private Base64()
Constructor for the Base64 object

Method Detail

encodeChunk

private static final byte[] encodeChunk(byte[] input,
                                        int len)
Encode up to 3 bytes of binary data as 4 bytes of printable ASCII text.

Parameters:
input - A 3-byte long array of input.
len - The number of bytes (1, 2, or 3) that are significant in the input.
Returns:
A 4-byte array of printable characters that represent the Radix-64 encoding of the input. The output will include padding ('=' characters) if not all 3 bytes of the input were significant.

decodeChunk

private static final int decodeChunk(byte[] input,
                                     byte[] output)
Decode 4 bytes of printable ASCII text into up to 3 bytes of binary data.

Parameters:
input - A 4-byte long array of input bytes.
output - A 3-byte long array in which up to 3 bytes of decoded output will be stored.
Returns:
The number of bytes decoded (1, 2, or 3).

toBase64

public static final java.lang.String toBase64(byte[] bin)
Converts an array of binary data into a String in Base64 encoding.

Parameters:
bin - The bytes to be converted into a base64 encoded equivalent
Returns:
The base64 encoded data

toHex16

public static final java.lang.String toHex16(byte[] bin)
Converts an array of binary data into a String in Hex16 encoding. High nibble comes first.

Parameters:
bin - The bytes to be converted into a hex16 encoded equivalent
Returns:
The hex16 encoded data

toBinary

public static final int toBinary(java.lang.String toconv,
                                 byte[] target)
Convert a String in Base64 encoding into binary data in the given array. Its up to the caller to pass an array of appropriate size. If it is too large, not everything will be filled. If it is too short, an exception will be thrown.

Parameters:
toconv - The String to be converted from base64 to real bytes
target - The target space for the bytes
Returns:
The number of converted bytes

toBinary

public static final byte[] toBinary(java.lang.String toconv)
Converty a String in Base64 encoding into binary data.

Parameters:
toconv - The String to be converted from base64 to real bytes
Returns:
The real bytes

QJCC homepage