All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oreilly.servlet.Base64Encoder

java.lang.Object
   |
   +----java.io.OutputStream
           |
           +----java.io.FilterOutputStream
                   |
                   +----com.oreilly.servlet.Base64Encoder

public class Base64Encoder
extends FilterOutputStream
A class to encode Base64 streams and strings. See RFC 1521 section 5.2 for details of the Base64 algorithm.

This class can be used for encoding strings:

 String unencoded = "webmaster:try2gueSS";
 String encoded = Base64Encoder.encode(unencoded);
 
or for encoding streams:
 OutputStream out = new Base64Encoder(System.out);
 

Version:
1.1, 2000/11/17, fixed bug with sign bit for char values
Author:
Jason Hunter, Copyright © 2000

Constructor Index

 o Base64Encoder(OutputStream)
Constructs a new Base64 encoder that writes output to the given OutputStream.

Method Index

 o close()
Closes the stream, this MUST be called to ensure proper padding is written to the end of the output stream.
 o encode(String)
Returns the encoded form of the given unencoded string.
 o main(String[])
 o write(byte[], int, int)
Writes the given byte array to the output stream in an encoded form.
 o write(int)
Writes the given byte to the output stream in an encoded form.

Constructors

 o Base64Encoder
 public Base64Encoder(OutputStream out)
Constructs a new Base64 encoder that writes output to the given OutputStream.

Parameters:
out - the output stream

Methods

 o write
 public void write(int b) throws IOException
Writes the given byte to the output stream in an encoded form.

Throws: IOException
if an I/O error occurs
Overrides:
write in class FilterOutputStream
 o write
 public void write(byte b[],
                   int off,
                   int len) throws IOException
Writes the given byte array to the output stream in an encoded form.

Parameters:
b - the data to be written
off - the start offset of the data
len - the length of the data
Throws: IOException
if an I/O error occurs
Overrides:
write in class FilterOutputStream
 o close
 public void close() throws IOException
Closes the stream, this MUST be called to ensure proper padding is written to the end of the output stream.

Throws: IOException
if an I/O error occurs
Overrides:
close in class FilterOutputStream
 o encode
 public static String encode(String unencoded)
Returns the encoded form of the given unencoded string.

Parameters:
unencoded - the string to encode
Returns:
the encoded form of the unencoded string
 o main
 public static void main(String args[]) throws Exception

All Packages  Class Hierarchy  This Package  Previous  Next  Index