com.ibm.commons.util.io.base64
Class Base64OutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by com.ibm.commons.util.io.base64.Base64OutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
Base64.OutputStream

public class Base64OutputStream
extends java.io.FilterOutputStream

A Base64 content transfer encoding filter stream.

From RFC 2045, section 6.8:

The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable. The encoding and decoding algorithms are simple, but the encoded data are consistently only about 33 percent larger than the unencoded data.


Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
Base64OutputStream(java.io.OutputStream out)
          Default constructor.
Base64OutputStream(java.io.OutputStream out, int lineLength)
          Constructor.
 
Method Summary
 void close()
          Closes this output stream and releases any system resources associated with this stream.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this output stream.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int ch)
          Writes the specified byte to this output stream.
 
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)
Default constructor. This constructs a Base64OutputStream with a line length of 76.

Parameters:
out - the underlying output stream to encode

Base64OutputStream

public Base64OutputStream(java.io.OutputStream out,
                          int lineLength)
Constructor.

Parameters:
out - the underlying output stream to encode
lineLength - the line length
Method Detail

write

public void write(int ch)
           throws java.io.IOException
Writes the specified byte to this output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
ch - character to write/encode
Throws:
java.io.IOException - IO Exception occurred

write

public void write(byte[] b)
           throws java.io.IOException
Writes b.length bytes from the specified byte array to this output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - buffer to write/encode
Throws:
java.io.IOException - IO Exception occurred

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - buffer to write/encode
off - offset to start of buffer to write/encode
len - number of bytes from buffer to write/encode
Throws:
java.io.IOException - IO Exception occurred

flush

public void flush()
           throws java.io.IOException
Flushes this output stream and forces any buffered output bytes to be written out.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.FilterOutputStream
Throws:
java.io.IOException - IO Exception occurred

close

public void close()
           throws java.io.IOException
Closes this output stream and releases any system resources associated with this stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterOutputStream
Throws:
java.io.IOException - IO Exception occurred