org.mortbay.util
Class B64Code

java.lang.Object
  |
  +--org.mortbay.util.B64Code

public class B64Code
extends java.lang.Object

Fast B64 Encoder/Decoder as described in RFC 1421.

Does not insert or interpret whitespace as described in RFC 1521. If you require this you must pre/post process your data.

Note that in a web context the usual case is to not want linebreaks or other white space in the encoded output.

Version:
$Revision: 1.4 $
Author:
Brett Sealey (bretts), Greg Wilkins (gregw)

Constructor Summary
B64Code()
           
 
Method Summary
static byte[] decode(char[] b)
          Fast Base 64 decode as described in RFC 1421.
static java.lang.String decode(java.lang.String s)
          Base 64 decode as described in RFC 1421.
static java.lang.String decode(java.lang.String s, java.lang.String charEncoding)
          Base 64 decode as described in RFC 1421.
static char[] encode(byte[] b)
          Fast Base 64 encode as described in RFC 1421.
static java.lang.String encode(java.lang.String s)
          Base 64 encode as described in RFC 1421.
static java.lang.String encode(java.lang.String s, java.lang.String charEncoding)
          Base 64 encode as described in RFC 1421.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

B64Code

public B64Code()
Method Detail

encode

public static java.lang.String encode(java.lang.String s)
Base 64 encode as described in RFC 1421.

Does not insert whitespace as described in RFC 1521.

Parameters:
s - String to encode.
Returns:
String containing the encoded form of the input.

encode

public static java.lang.String encode(java.lang.String s,
                                      java.lang.String charEncoding)
                               throws java.io.UnsupportedEncodingException
Base 64 encode as described in RFC 1421.

Does not insert whitespace as described in RFC 1521.

Parameters:
s - String to encode.
charEncoding - String representing the name of the character encoding of the provided input String.
Returns:
String containing the encoded form of the input.
java.io.UnsupportedEncodingException

encode

public static char[] encode(byte[] b)
Fast Base 64 encode as described in RFC 1421.

Does not insert whitespace as described in RFC 1521.

Avoids creating extra copies of the input/output.

Parameters:
b - byte array to encode.
Returns:
char array containing the encoded form of the input.

decode

public static java.lang.String decode(java.lang.String s)
Base 64 decode as described in RFC 1421.

Does not attempt to cope with extra whitespace as described in RFC 1521.

Parameters:
s - String to decode
Returns:
String decoded byte array.

decode

public static java.lang.String decode(java.lang.String s,
                                      java.lang.String charEncoding)
                               throws java.io.UnsupportedEncodingException
Base 64 decode as described in RFC 1421.

Does not attempt to cope with extra whitespace as described in RFC 1521.

Parameters:
s - String to decode
charEncoding - String representing the character encoding used to map the decoded bytes into a String.
Returns:
String decoded byte array.
java.io.UnsupportedEncodingException

decode

public static byte[] decode(char[] b)
Fast Base 64 decode as described in RFC 1421.

Does not attempt to cope with extra whitespace as described in RFC 1521.

Avoids creating extra copies of the input/output.

Note this code has been flattened for performance.

Parameters:
b - char array to decode.
Returns:
byte array containing the decoded form of the input.
Throws:
java.lang.IllegalArgumentException - if the input is not a valid B64 encoding.


Copyright ? 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.