java.lang.Object
|
+--java.io.InputStream
|
+--de.cgarbs.io.MUXInputStream
A multiplexing input stream. Data read from this input stream is written unchanged to none, one or multiple attached output streams. The attached output streams can be added, removed, activated and deactivated at any time.
This is particularly useful for debugging purposes. If you have an input stream in_old (e.g. reading from a socket) you can easily debug it's data to System.out:
MUXInputStream in_new = new MUXInputStream(in_old); in_old.add(System.out);
This class is licensed under the GNU LESSER GENERAL PUBLIC LICENSE.
| Constructor Summary | |
MUXInputStream(java.io.InputStream in)
Creates a new MUXInputStream on top of an existing input stream. |
|
| 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. |
int |
available()
Returns the number of bytes that can be read from the underlying input stream without blocking. |
void |
clear()
Removes all output streams from the list. |
void |
close()
Closes the input stream as well as all (active and inactive) output streams in the list and releases any system resources associated with the streams. |
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. |
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 |
mark(int readlimit)
Marks the current position in the underlying input stream. |
boolean |
markSupported()
Tests if the underlying input stream supports the mark and reset methods. |
int |
read()
Reads the next byte of data from the underlying input stream. |
int |
read(byte[] b)
Reads up to b.length bytes of data from the underlying input stream into an array of bytes. |
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from the underlying input stream into an array of bytes. |
void |
remove(java.io.OutputStream o)
Removes an output stream from the list. |
void |
reset()
Repositions this stream to the position at the time the mark method was last called on the unserlying input stream. |
int |
size()
Returns the number of output streams in the list. |
long |
skip(long n)
Skips over and discards n bytes of data from the underlying input stream. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public MUXInputStream(java.io.InputStream in)
in - the underlying input stream| Method Detail |
public int available()
throws java.io.IOException
public void mark(int readlimit)
The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.
readlimit - the maximum limit of bytes that can be read before the
mark position becomes invalid.
public void reset()
throws java.io.IOException
public boolean markSupported()
public long skip(long n)
throws java.io.IOException
n - the number of bytes to be skipped.
public int read()
throws java.io.IOException
public int read(byte[] b)
throws java.io.IOException
b - the buffer into which the data is read.
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
b - the buffer into which the data is read.off - the start offset of the data.len - the maximum number of bytes read.
public void close()
throws java.io.IOException
public 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)