com.aliasi.io
Class Reporters

java.lang.Object
  extended by com.aliasi.io.Reporters

public class Reporters
extends Object

The Reporters utility class provides static factory methods for the creation of various instances of Reporter. The reporters created wrap various output methods from writers to streams to files to standard output to nothing.

Thread Safety

Each of the primitive implementations is itself thread safe because calls to report are synchronized.

The compound reporter produced by tee(Reporter[]) will be thread safe if each of its contained reporters is thread safe.

Serializability

None of the reporters are serializable.

Since:
Lingpipe3.8
Version:
3.8
Author:
Bob Carpenter

Method Summary
static Reporter file(File f, String encoding)
          Return a reporter that writes to the specified file using the specified encoding.
static Reporter silent()
          Returns a silent reporter that writes its output nowhere.
static Reporter stdOut()
          Return a reporter that writes to standard output using the UTF-8 character encoding.
static Reporter stream(OutputStream out, String encoding)
          Return a reporter that writes to the specified output stream using the specified encoding.
static Reporter tee(Reporter... reporters)
          Returns a compound reporter that sends reports to all of the specified reporters.
static Reporter writer(Writer writer)
          Return a reporter that writes to the specified print writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writer

public static Reporter writer(Writer writer)
Return a reporter that writes to the specified print writer.

The initial log level is LogLevel.NONE. This may be reset using the method Reporter.setLevel(LogLevel).

Parameters:
writer - Writer to use for reporting.
Returns:
The writer-based reporter.

stream

public static Reporter stream(OutputStream out,
                              String encoding)
                       throws UnsupportedCharsetException
Return a reporter that writes to the specified output stream using the specified encoding.

Parameters:
out - Output stream to which to write.
encoding - Encoding to use for writing.
Returns:
The stream-based reporter.
Throws:
UnsupportedCharsetException - If the encoding is not supported.

file

public static Reporter file(File f,
                            String encoding)
                     throws IOException
Return a reporter that writes to the specified file using the specified encoding.

Parameters:
f - File to which to write.
encoding - Character encoding to use for writing.
Returns:
The file-based reporter.
Throws:
UnsupportedCharsetException - If the encoding is not supported.
IOException - If the file is not found.

stdOut

public static Reporter stdOut()
Return a reporter that writes to standard output using the UTF-8 character encoding. The standard output stream is retrieved through System.out.

To write to standard output using a different character set, use the factory method stream(OutputStream,String) with the stream set to System.out.

Returns:
The standard-out-based reporter.
Throws:
UnsupportedCharsetException - If this platform does not support UTF-8; the Java specification requires UTF-8 support, so this should not occur on standard platforms.

tee

public static Reporter tee(Reporter... reporters)
Returns a compound reporter that sends reports to all of the specified reporters.

The compound reporter may have its log level set like any reporter. Only reports at a log level whose severity is enabled are reported to the contained reporters through their report methods.

To allow the compound reporter to control logging levels for the contained reporters, set the contained reporters log levels to LogLevel.ALL so that they report all messages sent to them by the compound reporter. For instance:

 for (Reporter reporter : reporters)
     reporter.setLevel(LogLevel.ALL);
 Reporter rep = Reporters.tee(reporters);
 rep.setLevel(LogLevel.DEBUG);
creates a compound logger printing messages to all contained reporters at or above the debug level of severity.

Parameters:
reporters - A variable-length list of reporters.

silent

public static Reporter silent()
Returns a silent reporter that writes its output nowhere. This is like piping a file to dev/null on a Unix machine.

The log levle on this reporter is fixed at LogLevel.NONE. Although levels may be set on silent reporters, no matter what level is set, nothing is output.

There is only a single silent reporter that is returned for all calls to this method.

Returns:
The silent reporter.