- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- ij.io.LogStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class LogStream extends java.io.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/)
-
-
Constructor Summary
Constructors Constructor Description LogStream()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
static java.io.PrintStream
getCurrentErrStream()
Returns the redirection stream forSystem.err
if it exists.static java.io.PrintStream
getCurrentOutStream()
Returns the redirection stream forSystem.out
if it exists.static void
redirectSystem()
Redirects all output sent toSystem.out
andSystem.err
to ImageJ's log console using the default prefixes.static void
redirectSystem(boolean redirect)
Redirects all output sent toSystem.out
andSystem.err
to ImageJ's log console using the default prefixes.static void
redirectSystemErr(java.lang.String prefix)
Redirects all output sent toSystem.err
to ImageJ's log console.static void
redirectSystemOut(java.lang.String prefix)
Redirects all output sent toSystem.out
to ImageJ's log console.static void
revertSystem()
Use this method to revert bothSystem.out
andSystem.err
to their original output streams.static void
revertSystemErr()
Use this method to revertSystem.err
to the original output stream.static void
revertSystemOut()
Use this method to revertSystem.out
to the original output stream.void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Method Detail
-
redirectSystem
public static void redirectSystem(boolean redirect)
Redirects all output sent toSystem.out
andSystem.err
to ImageJ's log console using the default prefixes.
-
redirectSystem
public static void redirectSystem()
Redirects all output sent toSystem.out
andSystem.err
to 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(java.lang.String prefix)
Redirects all output sent toSystem.out
to ImageJ's log console.- Parameters:
prefix
- The prefix string inserted at the start of each output line. Passnull
to use the default prefix or an empty string to remove the prefix.
-
redirectSystemErr
public static void redirectSystemErr(java.lang.String prefix)
Redirects all output sent toSystem.err
to ImageJ's log console.- Parameters:
prefix
- The prefix string inserted at the start of each output line. Passnull
to use the default prefix or an empty string to remove the prefix.
-
getCurrentOutStream
public static java.io.PrintStream getCurrentOutStream()
Returns the redirection stream forSystem.out
if it exists. Note that a reference to the current output stream can also be obtained directly from theSystem.out
field.- Returns:
- A reference to the
PrintStream
object currently substitutingSystem.out
ornull
of ifSystem.out
is currently not redirected.
-
getCurrentErrStream
public static java.io.PrintStream getCurrentErrStream()
Returns the redirection stream forSystem.err
if it exists. Note that a reference to the current output stream can also be obtained directly from theSystem.err
field.- Returns:
- A reference to the
PrintStream
object currently substitutingSystem.err
ornull
of ifSystem.err
is currently not redirected.
-
revertSystem
public static void revertSystem()
Use this method to revert bothSystem.out
andSystem.err
to their original output streams.
-
revertSystemOut
public static void revertSystemOut()
Use this method to revertSystem.out
to the original output stream.
-
revertSystemErr
public static void revertSystemErr()
Use this method to revertSystem.err
to the original output stream.
-
write
public void write(byte[] b)
- Overrides:
write
in classjava.io.FilterOutputStream
-
write
public void write(byte[] b, int off, int len)
- Overrides:
write
in classjava.io.PrintStream
-
write
public void write(int b)
- Overrides:
write
in classjava.io.PrintStream
-
flush
public void flush()
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.PrintStream
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.PrintStream
-
-