public class Tee extends java.io.PrintStream implements RevisionHandler
import java.io.*; import weka.core.Tee; ... // stdout Tee teeOut = new Tee(System.out); teeOut.add(new PrintStream(new FileOutputStream("out.txt")), true); System.setOut(teeOut); // stderr Tee teeErr = new Tee(System.err); teeErr.add(new PrintStream(new FileOutputStream("err.txt")), true); System.setOut(teeErr); ...
Constructor and Description |
---|
Tee()
initializes the object, with a default printstream.
|
Tee(java.io.PrintStream def)
initializes the object with the given default printstream, e.g.,
System.out.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.io.PrintStream p)
adds the given PrintStream to the list of streams, with NO timestamp and
NO prefix.
|
void |
add(java.io.PrintStream p,
boolean timestamp)
adds the given PrintStream to the list of streams, with NO prefix.
|
void |
add(java.io.PrintStream p,
boolean timestamp,
java.lang.String prefix)
adds the given PrintStream to the list of streams.
|
java.io.PrintStream |
append(char c)
Appends the specified character to this output stream.
|
java.io.PrintStream |
append(java.lang.CharSequence csq)
Appends the specified character sequence to this output stream.
|
java.io.PrintStream |
append(java.lang.CharSequence csq,
int start,
int end)
Appends a subsequence of the specified character sequence to this output
stream.
|
void |
clear()
removes all streams and places the default printstream, if any, again in
the list.
|
boolean |
contains(java.io.PrintStream p)
checks whether the given PrintStream is already in the list.
|
void |
flush()
flushes all the printstreams.
|
java.io.PrintStream |
get(int index)
returns the specified PrintStream from the list.
|
java.io.PrintStream |
getDefault()
returns the default printstrean, can be NULL.
|
java.lang.String |
getRevision()
Returns the revision string.
|
void |
print(boolean x)
prints the given boolean to the streams.
|
void |
print(char x)
prints the given char to the streams.
|
void |
print(char[] x)
prints the given char array to the streams.
|
void |
print(double x)
prints the given double to the streams.
|
void |
print(float x)
prints the given float to the streams.
|
void |
print(int x)
prints the given int to the streams.
|
void |
print(long x)
prints the given long to the streams.
|
void |
print(java.lang.Object x)
prints the given object to the streams.
|
void |
print(java.lang.String x)
prints the given string to the streams.
|
java.io.PrintStream |
printf(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
A convenience method to write a formatted string to this output stream
using the specified format string and arguments.
|
java.io.PrintStream |
printf(java.lang.String format,
java.lang.Object... args)
A convenience method to write a formatted string to this output stream
using the specified format string and arguments.
|
void |
println()
prints a new line to the streams.
|
void |
println(boolean x)
prints the given boolean to the streams.
|
void |
println(char x)
prints the given char to the streams.
|
void |
println(char[] x)
prints the given char array to the streams.
|
void |
println(double x)
prints the given double to the streams.
|
void |
println(float x)
prints the given float to the streams.
|
void |
println(int x)
prints the given int to the streams.
|
void |
println(long x)
prints the given long to the streams.
|
void |
println(java.lang.Object x)
prints the given object to the streams (for Throwables we print the stack
trace).
|
void |
println(java.lang.String x)
prints the given string to the streams.
|
java.io.PrintStream |
remove(int index)
removes the given PrintStream from the list.
|
java.io.PrintStream |
remove(java.io.PrintStream p)
removes the given PrintStream from the list.
|
int |
size()
returns the number of streams currently in the list.
|
java.lang.String |
toString()
returns only the classname and the number of streams.
|
void |
write(byte[] b)
Writes
b.length bytes to this output stream. |
void |
write(byte[] buf,
int off,
int len)
Writes
len bytes from the specified byte array starting at
offset off to this stream. |
void |
write(int b)
Writes the specified byte to this stream.
|
public Tee()
public Tee(java.io.PrintStream def)
def
- the default printstream, remains also after calling clear()public void clear()
getDefault()
public java.io.PrintStream getDefault()
m_Default
public void add(java.io.PrintStream p)
p
- the printstream to addpublic void add(java.io.PrintStream p, boolean timestamp)
p
- the printstream to addtimestamp
- whether to use timestamps or notpublic void add(java.io.PrintStream p, boolean timestamp, java.lang.String prefix)
p
- the printstream to addtimestamp
- whether to use timestamps or notprefix
- the prefix to usepublic java.io.PrintStream get(int index)
index
- the index of the PrintStream to returnpublic java.io.PrintStream remove(java.io.PrintStream p)
p
- the PrintStream to removepublic java.io.PrintStream remove(int index)
index
- the index of the PrintStream to removepublic boolean contains(java.io.PrintStream p)
p
- the PrintStream to look forpublic int size()
public void flush()
flush
in interface java.io.Flushable
flush
in class java.io.PrintStream
public void print(int x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(long x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(float x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(double x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(boolean x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(char x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(char[] x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(java.lang.String x)
print
in class java.io.PrintStream
x
- the object to printpublic void print(java.lang.Object x)
print
in class java.io.PrintStream
x
- the object to printpublic void println()
println
in class java.io.PrintStream
public void println(int x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(long x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(float x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(double x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(boolean x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(char x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(char[] x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(java.lang.String x)
println
in class java.io.PrintStream
x
- the object to printpublic void println(java.lang.Object x)
println
in class java.io.PrintStream
x
- the object to printpublic void write(byte[] buf, int off, int len)
len
bytes from the specified byte array starting at
offset off
to this stream. If automatic flushing is
enabled then the flush
method will be invoked.
Note that the bytes will be written as given; to write characters
that will be translated according to the platform's default character
encoding, use the print(char)
or println(char)
methods.
write
in class java.io.PrintStream
buf
- A byte arrayoff
- Offset from which to start taking byteslen
- Number of bytes to writepublic void write(int b)
flush
method will be
invoked.
Note that the byte is written as given; to write a character that
will be translated according to the platform's default character
encoding, use the print(char)
or println(char)
methods.
write
in class java.io.PrintStream
b
- The byte to be writtenprint(char)
,
println(char)
public void write(byte[] b) throws java.io.IOException
b.length
bytes to this output stream.
The write
method of FilterOutputStream
calls its write
method of three arguments with the
arguments b
, 0
, and
b.length
.
Note that this method does not call the one-argument
write
method of its underlying output stream with
the single argument b
.
write
in class java.io.FilterOutputStream
b
- the data to be written.java.io.IOException
- if an I/O error occurs.FilterOutputStream.write(byte[], int, int)
public java.io.PrintStream printf(java.lang.String format, java.lang.Object... args)
An invocation of this method of the form
out.printf(format, args)
behaves
in exactly the same way as the invocation
out.format(format, args)
printf
in class java.io.PrintStream
format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
The Java™ Virtual Machine Specification.
The behaviour on a
null
argument depends on the conversion.java.util.IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the
formatter class specification.java.lang.NullPointerException
- If the format
is null
public java.io.PrintStream printf(java.util.Locale l, java.lang.String format, java.lang.Object... args)
An invocation of this method of the form
out.printf(l, format, args)
behaves
in exactly the same way as the invocation
out.format(l, format, args)
printf
in class java.io.PrintStream
l
- The locale to apply during
formatting. If l
is null
then no localization
is applied.format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
The Java™ Virtual Machine Specification.
The behaviour on a
null
argument depends on the conversion.java.util.IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the
formatter class specification.java.lang.NullPointerException
- If the format
is null
public java.io.PrintStream append(char c)
An invocation of this method of the form out.append(c)
behaves in exactly the same way as the invocation
out.print(c)
append
in interface java.lang.Appendable
append
in class java.io.PrintStream
c
- The 16-bit character to appendpublic java.io.PrintStream append(java.lang.CharSequence csq)
An invocation of this method of the form out.append(csq)
behaves in exactly the same way as the invocation
out.print(csq.toString())
Depending on the specification of toString
for the
character sequence csq
, the entire sequence may not be
appended. For instance, invoking then toString
method of a
character buffer will return a subsequence whose content depends upon
the buffer's position and limit.
append
in interface java.lang.Appendable
append
in class java.io.PrintStream
csq
- The character sequence to append. If csq
is
null
, then the four characters "null"
are
appended to this output stream.public java.io.PrintStream append(java.lang.CharSequence csq, int start, int end)
An invocation of this method of the form
out.append(csq, start, end)
when
csq
is not null
, behaves in
exactly the same way as the invocation
out.print(csq.subSequence(start, end).toString())
append
in interface java.lang.Appendable
append
in class java.io.PrintStream
csq
- The character sequence from which a subsequence will be
appended. If csq
is null
, then characters
will be appended as if csq
contained the four
characters "null"
.start
- The index of the first character in the subsequenceend
- The index of the character following the last character in the
subsequencejava.lang.IndexOutOfBoundsException
- If start
or end
are negative, start
is greater than end
, or end
is greater than
csq.length()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getRevision()
getRevision
in interface RevisionHandler