java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
ij.io.LogStream
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()static PrintStreamReturns the redirection stream forSystem.errif it exists.static PrintStreamReturns the redirection stream forSystem.outif it exists.static voidRedirects all output sent toSystem.outandSystem.errto ImageJ's log console using the default prefixes.static voidredirectSystem(boolean redirect) Redirects all output sent toSystem.outandSystem.errto ImageJ's log console using the default prefixes.static voidredirectSystemErr(String prefix) Redirects all output sent toSystem.errto ImageJ's log console.static voidredirectSystemOut(String prefix) Redirects all output sent toSystem.outto ImageJ's log console.static voidUse this method to revert bothSystem.outandSystem.errto their original output streams.static voidUse this method to revertSystem.errto the original output stream.static voidUse this method to revertSystem.outto the original output stream.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(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, writeBytesMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
LogStream
public LogStream()
-
-
Method Details
-
redirectSystem
public static void redirectSystem(boolean redirect) Redirects all output sent toSystem.outandSystem.errto ImageJ's log console using the default prefixes. -
redirectSystem
public static void redirectSystem()Redirects all output sent toSystem.outandSystem.errto ImageJ's log console using the default prefixes. Alternatively useredirectSystemOut(String)andredirectSystemErr(String)to redirect the streams separately and to specify individual prefixes. -
redirectSystemOut
Redirects all output sent toSystem.outto ImageJ's log console.- Parameters:
prefix- The prefix string inserted at the start of each output line. Passnullto use the default prefix or an empty string to remove the prefix.
-
redirectSystemErr
Redirects all output sent toSystem.errto ImageJ's log console.- Parameters:
prefix- The prefix string inserted at the start of each output line. Passnullto use the default prefix or an empty string to remove the prefix.
-
getCurrentOutStream
Returns the redirection stream forSystem.outif it exists. Note that a reference to the current output stream can also be obtained directly from theSystem.outfield.- Returns:
- A reference to the
PrintStreamobject currently substitutingSystem.outornullof ifSystem.outis currently not redirected.
-
getCurrentErrStream
Returns the redirection stream forSystem.errif it exists. Note that a reference to the current output stream can also be obtained directly from theSystem.errfield.- Returns:
- A reference to the
PrintStreamobject currently substitutingSystem.errornullof ifSystem.erris currently not redirected.
-
revertSystem
public static void revertSystem()Use this method to revert bothSystem.outandSystem.errto their original output streams. -
revertSystemOut
public static void revertSystemOut()Use this method to revertSystem.outto the original output stream. -
revertSystemErr
public static void revertSystemErr()Use this method to revertSystem.errto the original output stream. -
write
public void write(byte[] b) - Overrides:
writein classPrintStream
-
write
public void write(byte[] b, int off, int len) - Overrides:
writein classPrintStream
-
write
public void write(int b) - Overrides:
writein classPrintStream
-
flush
public void flush()- Specified by:
flushin interfaceFlushable- Overrides:
flushin classPrintStream
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classPrintStream
-