iaik.utils
Class Base64OutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--iaik.utils.Base64OutputStream
Direct Known Subclasses:
PemOutputStream

public class Base64OutputStream
extends FilterOutputStream

This class represents a FilterOutputStream that Base64 encodes the data passing through it. For writing Base64 encoded data to the underlying output stream, use one of the write methods.

Base64 is the encoding format used by Multipurpose Internet Mail Extension (Mime) for transmitting non-text material over text-only communications channels. Base64 is based on a 65-character subset of US-ASCII, enabling 6 bits to be represented per printable character (see RFC 1521).

This class may be used for Base64 encoding some given data and writing it to a file, e.g.:

 FileOutputStream fos = new FileOutputStream("test/base64.enc");
 Base64OutputStream base64os = new Base64OutputStream(fos);
 byte[] data = "Test Data to be Base64 encoded and written to a file".getBytes();
 base64os.write(data);
 base64os.flush();
 base64os.close();
 

Version:
File Revision 19
See Also:
Base64InputStream

Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
Base64OutputStream(OutputStream out)
          Creates a new Base64OutputStream to write Base64 encoded data to the specified underlying output stream.
Base64OutputStream(OutputStream out, byte[] lineBreak)
          Creates a new Base64OutputStream to write Base64 encoded data to the specified underlying output stream.
 
Method Summary
 void flush()
          Performs final processing and output to the output stream.
static byte[] getLineBreak()
          Gets the line break delimiter; is CRLF (0x0D, 0x0A).
static void setLineBreak(byte[] lineBreak)
          Stets the lineBreak delimiter to be used throughout the application; default is CRLF (0x0D, 0x0A).
 void write(byte[] in, int inOff, int inLen)
          Base64 encodes the the specified number of bytes and writes them to the underlying output stream.
 void write(int b)
          Base64 encodes the given byte and writes it to the underlying output stream.
 
Methods inherited from class java.io.FilterOutputStream
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Base64OutputStream

public Base64OutputStream(OutputStream out,
                          byte[] lineBreak)
Creates a new Base64OutputStream to write Base64 encoded data to the specified underlying output stream.
Parameters:
out - - the underlying output stream.
lineBreak - - the lineBreak the line break delimiter to be used; if null or of zero length, the currently static set line break delimiter CRLF (0x0D, 0x0A) will be used

Base64OutputStream

public Base64OutputStream(OutputStream out)
Creates a new Base64OutputStream to write Base64 encoded data to the specified underlying output stream.
Parameters:
out - - the underlying output stream.
Method Detail

setLineBreak

public static void setLineBreak(byte[] lineBreak)
Stets the lineBreak delimiter to be used throughout the application; default is CRLF (0x0D, 0x0A).
Parameters:
lineBreak - the lineBreak to be used
Throws:
IllegalArgumentException - if lineBreak is null or of zero length

getLineBreak

public static byte[] getLineBreak()
Gets the line break delimiter; is CRLF (0x0D, 0x0A).
Returns:
the line break used

write

public void write(int b)
           throws IOException
Base64 encodes the given byte and writes it to the underlying output stream.
Overrides:
write in class FilterOutputStream
Parameters:
b - the byte to be Base64 encoded.
Throws:
IOException - if an I/O error occurs.

write

public void write(byte[] in,
                  int inOff,
                  int inLen)
           throws IOException
Base64 encodes the the specified number of bytes and writes them to the underlying output stream.

The data to be processed is given in an input byte array. Beginning at inOff, this method only encodes the first inLen bytes and writes them to the underlying output stream.

Overrides:
write in class FilterOutputStream
Parameters:
in - the buffer containing the bytes to be Base64 encoded
inOff - the offset indicating the start position within the input byte array
inLen - the number of bytes to be processed
Throws:
IOException - if an I/O error occurs.

flush

public void flush()
           throws IOException
Performs final processing and output to the output stream.
Overrides:
flush in class FilterOutputStream
Throws:
IOException - If an error occurs.

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK