Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.cybertivity.powerjournal
Class Base64  view Base64 download Base64.java

java.lang.Object
  extended bycom.cybertivity.powerjournal.Base64

public class Base64
extends java.lang.Object

Encode arbitrary binary into printable ASCII using BASE64 encoding. very loosely based on the Base64 Reader by Dr. Mark Thornton Optrak Distribution Software Ltd. http://www.optrak.co.uk and Kevin Kelley's http://www.ruralnet.net/~kelley/java/Base64.java Base64 is a way of encoding 8-bit characters using only ASCII printable characters. The spec is described in RFC 2045. Base64 is a scheme where 3 bytes are concatenated, then split to form 4 groups of 6-bits each; and each 6-bits gets translated to an encoded printable ASCII character, via a table lookup. An encoded string is therefore longer than the original by about 1/3. The "=" character is used to pad the end. Base64 is used, among other things, to encode the user:password string in an Authorization: header for HTTP. Don't confuse Base64 with x-www-form-urlencoded which is handled by Java.net.URLEncoder.encode/decode If you wanted to encode a giant file, you could do it in large chunks that are even multiples of 3 bytes, except for the last chunk, and append the outputs. version 1.1 1999 December 04 -- more symmetrical encoding algorithm. more accurate StringBuffer allocation size. version 1.0 1999 December 03 -- posted in comp.lang.java.programmer.


Field Summary
(package private) static int[] charToValue
          binary value encoded by a given letter of the alphabet 0..63
private static boolean debug
          used to disable test driver
(package private) static int IGNORE
          Marker value for chars we just ignore, e.g.
private static int lineLength
          max chars per line.
(package private) static java.lang.String lineSeparator
          how we separate lines, e.g.
(package private) static int PAD
          Marker for = trailing pad
(package private) static char[] valueToChar
          letter of the alphabet used to encode binary values 0..63
 
Constructor Summary
Base64()
           
 
Method Summary
static byte[] decode(java.lang.String s)
          decode a well-formed complete Base64 string back into an array of bytes.
static java.lang.String encode(byte[] b)
          Encode an arbitrary array of bytes as Base64 printable ASCII.
static void main(java.lang.String[] args)
          test driver
static void setLineLength(int length)
          determines how long the lines are that are generated by encode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineSeparator

static java.lang.String lineSeparator
how we separate lines, e.g. \n, \r\n, \r etc.


lineLength

private static int lineLength
max chars per line. A multiple of 4.


valueToChar

static final char[] valueToChar
letter of the alphabet used to encode binary values 0..63


charToValue

static final int[] charToValue
binary value encoded by a given letter of the alphabet 0..63


IGNORE

static final int IGNORE
Marker value for chars we just ignore, e.g. \n \r high ascii

See Also:
Constant Field Values

PAD

static final int PAD
Marker for = trailing pad

See Also:
Constant Field Values

debug

private static final boolean debug
used to disable test driver

See Also:
Constant Field Values
Constructor Detail

Base64

public Base64()
Method Detail

encode

public static java.lang.String encode(byte[] b)
Encode an arbitrary array of bytes as Base64 printable ASCII. It will be broken into lines of 72 chars each. The last line is not terminated with a line separator.


decode

public static byte[] decode(java.lang.String s)
decode a well-formed complete Base64 string back into an array of bytes.


setLineLength

public static void setLineLength(int length)
determines how long the lines are that are generated by encode. Ignored by decode.


main

public static void main(java.lang.String[] args)
test driver