iaik.utils
Class Base64OutputStream

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

public class Base64OutputStream
extends java.io.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();
 

See Also:
Base64InputStream

Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
Base64OutputStream(java.io.OutputStream out)
          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.
 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(java.io.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

write

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

write

public void write(byte[] in,
                  int inOff,
                  int inLen)
           throws java.io.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 java.io.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:
java.io.IOException - if an I/O error occurs.

flush

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