|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
bcds.tools.ThreadedPrintStream
public class ThreadedPrintStream
Implements a PrintStream that offers a separate "channel" (output stream) to each thread in a multithreaded program. In fact, an instance of this class acts a proxy to the real, user-provided output streams. Its intended purpose is to replace System.out and/or System.err.
The main ideas for this implementation come from: http://maiaco.com/articles/java/threadOut.php
EXAMPLE OF USAGE:
...
public static void main(Strings...args) {
System.setOut(new ThreadedPrintStream(System.out));
...
Thread th = new Runnable() {
...
public void run()
{
... os = ... // some OutputStream instance.
((ThreadedPrintStream) (System.out)).setThisThreadOutput(os);
...
}
};
...
}
| Field Summary |
|---|
| Fields inherited from class java.io.FilterOutputStream |
|---|
out |
| Constructor Summary | |
|---|---|
ThreadedPrintStream(java.io.OutputStream original_stream)
Creates a new instance that sends all output to original_stream. |
|
| Method Summary | |
|---|---|
boolean |
checkError()
Flushes the output stream and returns false (always). |
void |
clearError()
|
void |
close()
|
void |
flush()
|
java.io.OutputStream |
getThisThreadOutput()
Returns the output stream for the current thread. |
void |
setThisThreadOutput(java.io.OutputStream os)
Sets the output stream for the calling thread. |
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
| Methods inherited from class java.io.PrintStream |
|---|
append, append, append, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError |
| 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 |
|---|
public ThreadedPrintStream(java.io.OutputStream original_stream)
original_stream. If this instance is shared among
several threads (as would be the case if it is used as
a System.out replacement, for example), each thread will
also write to original_stream automatically until
a call to setThisThreadOutput is called.
| Method Detail |
|---|
public void setThisThreadOutput(java.io.OutputStream os)
public java.io.OutputStream getThisThreadOutput()
public void close()
close in interface java.io.Closeableclose in class java.io.PrintStreampublic void flush()
flush in interface java.io.Flushableflush in class java.io.PrintStream
public void write(byte[] b,
int off,
int len)
write in class java.io.PrintStreampublic void write(int b)
write in class java.io.PrintStreampublic boolean checkError()
checkError in class java.io.PrintStreampublic void clearError()
clearError in class java.io.PrintStream
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||