org.metasyntactic.io
Class Base64OutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--org.metasyntactic.io.Base64OutputStream

public class Base64OutputStream
extends java.io.FilterOutputStream


Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
Base64OutputStream(java.io.OutputStream out)
           
Base64OutputStream(java.io.OutputStream out, boolean finishOnFlush)
          The constructor for the encoding output stream.
 
Method Summary
 void close()
           
 void flush()
          This method is to write all buffered data to its destination.
static void main(java.lang.String[] args)
           
 void setFinishOnFlush(boolean value)
          Sets the value of finishOnFlush.
 void write(byte[] data, int off, int len)
           
 void write(int b)
          Encodes and writes a single byte to the output stream.
 
Methods inherited from class java.io.FilterOutputStream
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)

Base64OutputStream

public Base64OutputStream(java.io.OutputStream out,
                          boolean finishOnFlush)
The constructor for the encoding output stream.

Parameters:
out - the underlying output stream.
finishOnFlush - controls the behaviour of the flush method.
See Also:
flush()
Method Detail

setFinishOnFlush

public void setFinishOnFlush(boolean value)
Sets the value of finishOnFlush.

Parameters:
value - the new value.
See Also:
org.tsx.mnl.io.base64.Base64OutputStream#flush

write

public void write(int b)
           throws java.io.IOException
Encodes and writes a single byte to the output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the byte to be written.
java.io.IOException

write

public void write(byte[] data,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
java.io.IOException

flush

public void flush()
           throws java.io.IOException
This method is to write all buffered data to its destination. With a base64 encoding there arises a problem: if an encoding character isn't completly known yet because its value depends partially on the last byte written and partially on the next byte to be written, then flush can't write it without assuming that there will be no more bytes coming. The behaviour for flush can therefore be controlled by the flag finishOnFlush when the stream is created. If the flag is set, flush will assume that no more data is to be written after flush has been called, thus effectivly finishing the stream of encoded data. This behaviour is especially useful, when the Base64OutputStream is created with an underlying output stream that contains mixed content. In this case, we cannot call close on the Base64OutputStream because this would make the underlying OutputStream unusable as well.

Overrides:
flush in class java.io.FilterOutputStream
java.io.IOException
See Also:
org.tsx.mnl.io.base64.Base64OutputStream, OutputStream.flush()

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.io.FilterOutputStream
java.io.IOException

main

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