Module ij
Package ij.io

# Class LogStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
ij.io.LogStream

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

public class LogStream extends PrintStream
This class provides the functionality to divert output sent to the System.out and System.err streams to ImageJ's log console. The purpose is to allow use of existing Java classes or writing new generic Java classes that only output to System.out and are thus less dependent on ImageJ. See the ImageJ plugin Redirect_System_Streams at http://staff.fh-hagenberg.at/burger/imagej/ for usage examples.

Author:
  Wilhelm Burger (wilbur at ieee.org) See Also: Redirect_System_Streams (http://staff.fh-hagenberg.at/burger/imagej/)

## Field Summary

### Fields inherited from class java.io.FilterOutputStream

`out`

## Constructor Summary

Constructors
Constructor
Description
`LogStream()`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
`void`
`flush()`
`static PrintStream`
`getCurrentErrStream()`
Returns the redirection stream for `System.err` if it exists.
`static PrintStream`
`getCurrentOutStream()`
Returns the redirection stream for `System.out` if it exists.
`static void`
`redirectSystem()`
Redirects all output sent to `System.out` and `System.err` to ImageJ's log console using the default prefixes.
`static void`
`redirectSystem(boolean redirect)`
Redirects all output sent to `System.out` and `System.err` to ImageJ's log console using the default prefixes.
`static void`
`redirectSystemErr(String prefix)`
Redirects all output sent to `System.err` to ImageJ's log console.
`static void`
`redirectSystemOut(String prefix)`
Redirects all output sent to `System.out` to ImageJ's log console.
`static void`
`revertSystem()`
Use this method to revert both `System.out` and `System.err` to their original output streams.
`static void`
`revertSystemErr()`
Use this method to revert`System.err` to the original output stream.
`static void`
`revertSystemOut()`
Use this method to revert`System.out` to the original output stream.
`void`
`write(byte[] b)`
`void`
`write(byte[] b, int off, int len)`
`void`
`write(int b)`

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

`append, append, append, charset, checkError, clearError, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, writeBytes`

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

`nullOutputStream`

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### LogStream

public LogStream()

## Method Details

### redirectSystem

public static void redirectSystem(boolean redirect)
Redirects all output sent to `System.out` and `System.err` to ImageJ's log console using the default prefixes.

### redirectSystem

public static void redirectSystem()
Redirects all output sent to `System.out` and `System.err` to ImageJ's log console using the default prefixes. Alternatively use `redirectSystemOut(String)` and `redirectSystemErr(String)` to redirect the streams separately and to specify individual prefixes.

### redirectSystemOut

public static void redirectSystemOut(String prefix)
Redirects all output sent to `System.out` to ImageJ's log console.

Parameters:
  `prefix` - The prefix string inserted at the start of each output line. Pass `null` to use the default prefix or an empty string to remove the prefix.

### redirectSystemErr

public static void redirectSystemErr(String prefix)
Redirects all output sent to `System.err` to ImageJ's log console.

Parameters:
  `prefix` - The prefix string inserted at the start of each output line. Pass `null` to use the default prefix or an empty string to remove the prefix.

### getCurrentOutStream

public static PrintStream getCurrentOutStream()
Returns the redirection stream for `System.out` if it exists. Note that a reference to the current output stream can also be obtained directly from the `System.out` field.

Returns:
  A reference to the `PrintStream` object currently substituting `System.out` or `null` of if `System.out` is currently not redirected.

### getCurrentErrStream

public static PrintStream getCurrentErrStream()
Returns the redirection stream for `System.err` if it exists. Note that a reference to the current output stream can also be obtained directly from the `System.err` field.

Returns:
  A reference to the `PrintStream` object currently substituting `System.err` or `null` of if `System.err` is currently not redirected.

### revertSystem

public static void revertSystem()
Use this method to revert both `System.out` and `System.err` to their original output streams.

### revertSystemOut

public static void revertSystemOut()
Use this method to revert`System.out` to the original output stream.

### revertSystemErr

public static void revertSystemErr()
Use this method to revert`System.err` to the original output stream.

### write

public void write(byte[] b)

Overrides:
  `write` in class `PrintStream`

### write

public void write(byte[] b, int off, int len)

Overrides:
  `write` in class `PrintStream`

### write

public void write(int b)

Overrides:
  `write` in class `PrintStream`

### flush

public void flush()

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

### close

public void close()

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Overrides:
  `close` in class `PrintStream`