de.bb.util
Class Mime

java.lang.Object
  extended by de.bb.util.Mime

public class Mime
extends java.lang.Object

Some helpfull static functions to handle Mime encoding and decoding.


Constructor Summary
Mime()
           
 
Method Summary
static byte[] createHeader(java.lang.String name)
          Create a Mime header for base64 encoded data.
static byte[] decode(byte[] x, int i, int stop)
          Do base64 decode of a byte array.
static byte[] encode(byte[] x)
          Do base64 encode of a byte array.
static byte[] encode(byte[] x, int width)
          Do base64 encode of a byte array.
static byte[] encodeFull(byte[] x, java.lang.String txt)
          Encode with header / footer.
static java.lang.String getParam(byte[] b, int off, java.lang.String param)
          Search a base64 parameter.
static byte[] searchDecode(byte[] x)
          Search an base64 encodede range.
static byte[] searchDecode(byte[] x, int off)
          Search an base64 encodede range.
static int strstr(byte[] s, int off, byte[] x)
          Search a byte array within another byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mime

public Mime()
Method Detail

decode

public static final byte[] decode(byte[] x,
                                  int i,
                                  int stop)
Do base64 decode of a byte array.

Parameters:
x - input data
i - an int specifying the start index into byte array
stop - an int specifying the stop index into byte array
Returns:
a new allocated byte array with decoded data

encode

public static final byte[] encode(byte[] x)
Do base64 encode of a byte array.

Parameters:
x - input data
Returns:
a new allocated byte array with encoded data - WITHOUT line breaks!

encode

public static final byte[] encode(byte[] x,
                                  int width)
Do base64 encode of a byte array.

Parameters:
x - input data
width - defines after how many input bytes a lf is added
Returns:
a new allocated byte array with encoded data

strstr

public static int strstr(byte[] s,
                         int off,
                         byte[] x)
Search a byte array within another byte array.

Parameters:
s - the searched byte array
off - an offset where the search starts
x - we are looking for these bytes
Returns:
the absolute offset or -1, when not found

searchDecode

public static byte[] searchDecode(byte[] x)
Search an base64 encodede range. Also header information, marked by a double lf, is skipped!

Parameters:
x - the bytes to be searched for "-----BEGIN ..." ... "-----END ..."
Returns:
a byte array containing the part within "-----BEGIN ..." ... "-----END ..."

searchDecode

public static byte[] searchDecode(byte[] x,
                                  int off)
Search an base64 encodede range. Also header information, marked by a double lf, is skipped!

Parameters:
x - the bytes to be searched for "-----BEGIN ..." ... "-----END ..."
off - an offset into the byte array
Returns:
a byte array containing the part within "-----BEGIN ..." ... "-----END ..."

getParam

public static java.lang.String getParam(byte[] b,
                                        int off,
                                        java.lang.String param)
Search a base64 parameter.

Parameters:
b - the searched bytes
off - offset to start the search
param - name of wanted parameter
Returns:
a String containing the parameter, or null when not found

encodeFull

public static byte[] encodeFull(byte[] x,
                                java.lang.String txt)
                         throws java.io.IOException
Encode with header / footer.

Parameters:
x - bytes to encode
txt - placed behind _----BEGIN and -----END
Returns:
an byte array with the encoded data
Throws:
java.io.IOException - on error

createHeader

public static byte[] createHeader(java.lang.String name)
Create a Mime header for base64 encoded data.

Parameters:
name - the name of the original file
Returns:
a byte array containing the MIME header, or null on error