com.tensegrity.generic.util
Class Base64

java.lang.Object
  extended bycom.tensegrity.generic.util.Base64

public class Base64
extends java.lang.Object

Base64 encoding encodes 3 bytes into 4 characters. Each set of 6 bits is encoded according to the ASCII2BASE64 map.

This class also holds inner Input- and OutputStream classes which are helpful when reading from / writing to streams.

Version:
$Id: Base64.java,v 1.13 2004/07/30 11:09:10 sr Exp $
Author:
Stepan Rutz, Andreas Ebbert

Nested Class Summary
static class Base64.InputStream
          Provides Base64 en- or decoding as an InputStream.
static class Base64.OutputStream
          Provides Base64 en- and decoding as an OutputStream.
 
Method Summary
static byte[] decode(java.lang.String input)
          Decodes the given Base64 string to the matching byte array.
protected static byte[] decode4to3(byte[] fourBytes)
          Decodes 4 given bytes to 3 bytes using BASE64-decoding.
protected static int decode4to3(byte[] source, int srcOffset, byte[] destination, int destOffset)
          Decodes 4 given bytes to 3 bytes using BASE64-decoding.
static byte[] decodeRaw(byte[] in)
          Decodes the given Base64 encoded bytes to the matching byte array.
static java.lang.String encode(byte[] in)
          Encodes the given byte array to the matching Base64 String.
protected static byte[] encode3to4(byte[] threeBytes)
          Encodes up to the first three bytes of array threeBytes and returns a four-byte array in Base64 notation.
static byte[] toByteArray(int[] source)
          Converts the given int array to a byte array.
static int[] toIntArray(byte[] source)
          Converts the given byte array to an int array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static final java.lang.String encode(byte[] in)
Encodes the given byte array to the matching Base64 String.

Parameters:
in - the array to encode.
Returns:
the matching Base64 String.

encode3to4

protected static byte[] encode3to4(byte[] threeBytes)
Encodes up to the first three bytes of array threeBytes and returns a four-byte array in Base64 notation.

Parameters:
threeBytes - the byte array to convert.
Returns:
four byte array in Base64 notation.

decode

public static final byte[] decode(java.lang.String input)
Decodes the given Base64 string to the matching byte array.

Parameters:
input - the String to decode.
Returns:
the decoded byte array.

decodeRaw

public static final byte[] decodeRaw(byte[] in)
Decodes the given Base64 encoded bytes to the matching byte array.

Parameters:
in - the bytes to decode.
Returns:
the decoded byte array.

decode4to3

protected static byte[] decode4to3(byte[] fourBytes)
Decodes 4 given bytes to 3 bytes using BASE64-decoding.

Parameters:
fourBytes - an array holding the 4 bytes to decode.
Returns:
an array holding the decoded bytes.

decode4to3

protected static int decode4to3(byte[] source,
                                int srcOffset,
                                byte[] destination,
                                int destOffset)
Decodes 4 given bytes to 3 bytes using BASE64-decoding.

Parameters:
source - the bytes to decode.
srcOffset - an offset telling where to find the 4 bytes to decode.
destination - an destination array for the decoded bytes.
destOffset - an offset telling where to store the decoded bytes.
Returns:
the decoded bytes as an int.

toByteArray

public static final byte[] toByteArray(int[] source)
Converts the given int array to a byte array. The returned arrays length is four times as large as the length of the given one.

Parameters:
source - the int array to convert.
Returns:
the converted byte array.

toIntArray

public static final int[] toIntArray(byte[] source)
Converts the given byte array to an int array. The returned arrays length is four times smaller than that of the given one.

Parameters:
source - the byte array to convert.
Returns:
the converted int array.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.