rabbit.io
Class MultiOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byrabbit.io.MultiOutputStream

public class MultiOutputStream
extends java.io.OutputStream

A class to handle automatic writing to several streams simultanius.


Field Summary
static int CLOSE_CURRENT
          how should exceptions be handled? by closing the stream causing it
static int RESPAWN_EXCEPTION
          Or by respawning the exception up
 
Constructor Summary
MultiOutputStream()
          Creates a new MultiOutputStream with no connected OutputStreams
MultiOutputStream(java.io.OutputStream os)
          Creates a new MultiOutputStream with one connected OutputStream
 
Method Summary
 void addOutputStream(java.io.OutputStream os)
          Connects one more OutputStream.
 void close()
          Close this stream.
 void flush()
          Write any pending data.
static void main(java.lang.String[] args)
          Simple self test
 void removeOutputStream(java.io.OutputStream os)
          Disconnects one of the underlaying streams.
 void setMode(int i)
          Sets the mode of this stream.
 void write(byte[] b)
          Write a byte array to this stream.
 void write(byte[] b, int off, int len)
          Write a byte array to this stream.
 void write(int b)
          Write a byte to this stream.
 void writeHTTPHeader(HTTPHeader header)
          Write a HTTPHeader on this stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLOSE_CURRENT

public static final int CLOSE_CURRENT
how should exceptions be handled? by closing the stream causing it

See Also:
Constant Field Values

RESPAWN_EXCEPTION

public static final int RESPAWN_EXCEPTION
Or by respawning the exception up

See Also:
Constant Field Values
Constructor Detail

MultiOutputStream

public MultiOutputStream()
Creates a new MultiOutputStream with no connected OutputStreams


MultiOutputStream

public MultiOutputStream(java.io.OutputStream os)
Creates a new MultiOutputStream with one connected OutputStream

Parameters:
os - the OutputStream to connect to
Method Detail

addOutputStream

public void addOutputStream(java.io.OutputStream os)
Connects one more OutputStream.

Parameters:
os - the new stream to connect

removeOutputStream

public void removeOutputStream(java.io.OutputStream os)
Disconnects one of the underlaying streams.

Parameters:
os - the stream to disconnect.

setMode

public void setMode(int i)
Sets the mode of this stream.

Parameters:
i - one of CLOSE_CURRENT(normal) and RESPAWN_EXCEPTION.

write

public void write(int b)
           throws java.io.IOException
Write a byte to this stream.

Parameters:
b - the byte to write.
Throws:
java.io.IOException - if the underlying stream does.

write

public void write(byte[] b)
           throws java.io.IOException
Write a byte array to this stream.

Parameters:
b - the byte array to write.
Throws:
java.io.IOException - if the underlying stream does.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Write a byte array to this stream.

Parameters:
b - the byte to write.
off - the starting offset.
len - the number of bytes to write.
Throws:
java.io.IOException - if the underlying stream does.

writeHTTPHeader

public void writeHTTPHeader(HTTPHeader header)
                     throws java.io.IOException
Write a HTTPHeader on this stream.

Parameters:
header - the HTTPHeader to write.
Throws:
java.io.IOException - if the header could not be written correctly.

flush

public void flush()
           throws java.io.IOException
Write any pending data.

Throws:
java.io.IOException - if the underlying stream does.

close

public void close()
           throws java.io.IOException
Close this stream.

Throws:
java.io.IOException - if the underlying stream does.

main

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