Package weka.core

# Class Tee

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
weka.core.Tee

All Implemented Interfaces:
  `Closeable`, `Flushable`, `Appendable`, `AutoCloseable`, `RevisionHandler`

public class Tee extends PrintStream implements RevisionHandler
This class pipelines print/println's to several PrintStreams. Useful for redirecting System.out and System.err to files etc.
E.g., for redirecting stderr/stdout to files with timestamps and:

        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);
        ...

Version:
  $Revision: 5057 $
Author:
  FracPete (fracpete at waikato dot ac dot nz)

## Constructor Summary

Constructors
Constructor
Description
`Tee()`
initializes the object, with a default printstream.
`Tee(PrintStream def)`
initializes the object with the given default printstream, e.g., System.out.

## Method Summary

Modifier and Type
Method
Description
`void`
`add(PrintStream p)`
adds the given PrintStream to the list of streams, with NO timestamp and NO prefix.
`void`
`add(PrintStream p, boolean timestamp)`
adds the given PrintStream to the list of streams, with NO prefix.
`void`
`add(PrintStream p, boolean timestamp, String prefix)`
adds the given PrintStream to the list of streams.
`void`
`clear()`
removes all streams and places the default printstream, if any, again in the list.
`boolean`
`contains(PrintStream p)`
checks whether the given PrintStream is already in the list.
`void`
`flush()`
flushes all the printstreams.
`PrintStream`
`get(int index)`
returns the specified PrintStream from the list.
`PrintStream`
`getDefault()`
returns the default printstrean, can be NULL.
`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(Object x)`
prints the given object to the streams.
`void`
`print(String x)`
prints the given string to the streams.
`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(Object x)`
prints the given object to the streams (for Throwables we print the stack trace).
`void`
`println(String x)`
prints the given string to the streams.
`PrintStream`
`remove(int index)`
removes the given PrintStream from the list.
`PrintStream`
`remove(PrintStream p)`
removes the given PrintStream from the list.
`int`
`size()`
returns the number of streams currently in the list.
`String`
`toString()`
returns only the classname and the number of streams.
`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.

### Methods inherited from class java.io.PrintStream

`append, append, append, charset, checkError, close, format, format, printf, printf, write, writeBytes`

### Methods inherited from class java.io.OutputStream

`nullOutputStream`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### Tee

public Tee()
initializes the object, with a default printstream.

### Tee

public Tee(PrintStream def)
initializes the object with the given default printstream, e.g., System.out.

Parameters:
  `def` - the default printstream, remains also after calling clear()

## Method Details

### clear

public void clear()
removes all streams and places the default printstream, if any, again in the list.

See Also:
  - `getDefault()`

### getDefault

public PrintStream getDefault()
returns the default printstrean, can be NULL.

Returns:
  the default printstream
See Also:
  - `m_Default`

### add

public void add(PrintStream p)
adds the given PrintStream to the list of streams, with NO timestamp and NO prefix.

Parameters:
  `p` - the printstream to add

### add

public void add(PrintStream p, boolean timestamp)
adds the given PrintStream to the list of streams, with NO prefix.

Parameters:
  `p` - the printstream to add
  `timestamp` - whether to use timestamps or not

### add

public void add(PrintStream p, boolean timestamp, String prefix)
adds the given PrintStream to the list of streams.

Parameters:
  `p` - the printstream to add
  `timestamp` - whether to use timestamps or not
  `prefix` - the prefix to use

### get

public PrintStream get(int index)
returns the specified PrintStream from the list.

Parameters:
  `index` - the index of the PrintStream to return
Returns:
  the specified PrintStream, or null if invalid index

### remove

public PrintStream remove(PrintStream p)
removes the given PrintStream from the list.

Parameters:
  `p` - the PrintStream to remove
Returns:
  returns the removed PrintStream if it could be removed, null otherwise

### remove

public PrintStream remove(int index)
removes the given PrintStream from the list.

Parameters:
  `index` - the index of the PrintStream to remove
Returns:
  returns the removed PrintStream if it could be removed, null otherwise

### contains

public boolean contains(PrintStream p)
checks whether the given PrintStream is already in the list.

Parameters:
  `p` - the PrintStream to look for
Returns:
  true if the PrintStream is in the list

### size

public int size()
returns the number of streams currently in the list.

Returns:
  the number of streams in the list

### flush

public void flush()
flushes all the printstreams.

Specified by:
  `flush` in interface `Flushable`
Overrides:
  `flush` in class `PrintStream`

### print

public void print(int x)
prints the given int to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(long x)
prints the given long to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(float x)
prints the given float to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(double x)
prints the given double to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(boolean x)
prints the given boolean to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(char x)
prints the given char to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(char[] x)
prints the given char array to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(String x)
prints the given string to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### print

public void print(Object x)
prints the given object to the streams.

Overrides:
  `print` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println()
prints a new line to the streams.

Overrides:
  `println` in class `PrintStream`

### println

public void println(int x)
prints the given int to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(long x)
prints the given long to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(float x)
prints the given float to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(double x)
prints the given double to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(boolean x)
prints the given boolean to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(char x)
prints the given char to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(char[] x)
prints the given char array to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(String x)
prints the given string to the streams.

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### println

public void println(Object x)
prints the given object to the streams (for Throwables we print the stack trace).

Overrides:
  `println` in class `PrintStream`
Parameters:
  `x` - the object to print

### write

public void write(byte[] buf, int off, int len)
Writes `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.

Overrides:
  `write` in class `PrintStream`
Parameters:
  `buf` - A byte array
  `off` - Offset from which to start taking bytes
  `len` - Number of bytes to write

### write

public void write(int b)
Writes the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the `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.

Overrides:
  `write` in class `PrintStream`
Parameters:
  `b` - The byte to be written
See Also:
  - `print(char)`
  - `println(char)`

### toString

public String toString()
returns only the classname and the number of streams.

Overrides:
  `toString` in class `Object`
Returns:
  only the classname and the number of streams

### getRevision

public String getRevision()
Returns the revision string.

Specified by:
  `getRevision` in interface `RevisionHandler`
Returns:
  the revision