- 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()static PrintStreamgetCurrentErrStream()Returns the redirection stream forSystem.errif it exists.static PrintStreamgetCurrentOutStream()Returns the redirection stream forSystem.outif it exists.static voidredirectSystem()Redirects 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 voidrevertSystem()Use this method to revert bothSystem.outandSystem.errto their original output streams.static voidrevertSystemErr()Use this method to revertSystem.errto the original output stream.static voidrevertSystemOut()Use 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, 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
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Method Detail
-
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
public static void redirectSystemOut(String prefix)
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
public static void redirectSystemErr(String prefix)
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
public static PrintStream 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
public static PrintStream 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 classFilterOutputStream
-
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
-
-