java.lang.Object
|
+--java.io.OutputStream
|
+--de.cgarbs.io.MUXOutputStream
A multiplexing output stream. Data written to this stream is written unchanged to none, one or multiple underlying output streams. Underlying output streams can be added, removed, activated and deactivated at any time.
This is particularly useful for debugging purposes. If you have an output stream out_old (e.g. writing to a socket) you can easily debug it's data to System.out:
MUXOutputStream out_new = new MUXOutputStream(out_old,System.out);
This class is licensed under the GNU LESSER GENERAL PUBLIC LICENSE.
| Constructor Summary | |
MUXOutputStream()
Creates a new MUXOutputStream with no underlying output streams. |
|
MUXOutputStream(java.io.OutputStream o)
Creates a new MUXOutputStream with one underlying output stream. |
|
MUXOutputStream(java.io.OutputStream o1,
java.io.OutputStream o2)
Creates a new MUXOutputStream with two underlying output streams. |
|
| Method Summary | |
void |
activate(java.io.OutputStream o)
Activates an output stream. |
void |
activateAll()
Activates all output streams. |
void |
activateOnly(java.io.OutputStream o)
Activates only one output stream. |
void |
add(java.io.OutputStream o)
Adds an output stream to the list. |
void |
clear()
Removes all output streams from the list. |
void |
close()
Closes all (active and inactive) output streams in the list. |
boolean |
contains(java.io.OutputStream o)
Tests if an output stream is contained in the list. |
void |
deactivate(java.io.OutputStream o)
Deactivates an output stream. |
void |
deactivateAll()
Deactivates all output streams. |
void |
flush()
Flushes all (activated and deactivated) output streams, forcing any bufferd bytes to be written. |
boolean |
isActive(java.io.OutputStream o)
Tests if an output stream is active. |
boolean |
isEmpty()
Tests if there are no output streams in the list. |
static void |
main(java.lang.String[] args)
Runs a demo of this class. |
void |
remove(java.io.OutputStream o)
Removes an output stream from the list. |
int |
size()
Returns the number of output streams in the list. |
void |
write(byte[] b)
Writes b.length bytes from the specified byte array to all active output streams. |
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array starting at off to all active output streams. |
void |
write(int j)
Writes the specified byte to all active output streams. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public MUXOutputStream()
public MUXOutputStream(java.io.OutputStream o)
o - the output stream
public MUXOutputStream(java.io.OutputStream o1,
java.io.OutputStream o2)
o1 - the first output streamo2 - the second output stream| Method Detail |
public void flush()
throws java.io.IOException
public void close()
throws java.io.IOException
public void write(int j)
throws java.io.IOException
j - the byte
public void write(byte[] b)
throws java.io.IOException
b - the data
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
b - the dataoff - the start offset in the datalen - the number of bytes to writepublic void remove(java.io.OutputStream o)
o - the output stream to remove from the listpublic int size()
public boolean contains(java.io.OutputStream o)
o - the output stream to testpublic void clear()
public void add(java.io.OutputStream o)
o - the output stream to addpublic boolean isEmpty()
public void activate(java.io.OutputStream o)
o - the output stream to activatepublic void deactivate(java.io.OutputStream o)
o - the output stream to deactivatepublic boolean isActive(java.io.OutputStream o)
o - the output stream to checkpublic void activateAll()
public void deactivateAll()
public void activateOnly(java.io.OutputStream o)
o - the output stream to activate
public static void main(java.lang.String[] args)
throws java.io.IOException
args - command line parameters (not used)