Class MirrorPrintStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- org.eclipse.epsilon.common.dt.console.MirrorPrintStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class MirrorPrintStream extends java.io.PrintStream
MirrorPrintStream is a PrintStream that mirrors all print/write operations into a file. Only the write(), check() and close() methods need overriding given that any of the print() and println() methods must go through these.- Since:
- 1.6
- Author:
- Horacio Hoyos Rodriguez
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
fileName
The file name.protected java.io.PrintStream
fileStream
The file stream.
-
Constructor Summary
Constructors Constructor Description MirrorPrintStream(java.io.OutputStream os)
Instantiates a MirrorPrintStream with autoflush.MirrorPrintStream(java.io.OutputStream os, boolean flush)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkError()
Return true if either stream has an error.protected void
clearError()
Clears the internal error state of this stream.void
close()
void
disableMirror()
Disable the mirror operation.void
flush()
void
mirrorToFile(java.lang.String fileName)
Enable mirroring to the given file.void
mirrorToFile(java.lang.String fileName, boolean append)
Enable mirroring to the given file.protected void
setError()
Sets the error state of the stream totrue
.void
write(byte[] x, int o, int l)
void
write(int x)
-
-
-
Method Detail
-
checkError
public boolean checkError()
Return true if either stream has an error.- Overrides:
checkError
in classjava.io.PrintStream
-
write
public void write(int x)
- Overrides:
write
in classjava.io.PrintStream
-
write
public void write(byte[] x, int o, int l)
- Overrides:
write
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
-
flush
public void flush()
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.PrintStream
-
mirrorToFile
public void mirrorToFile(java.lang.String fileName)
Enable mirroring to the given file. If there is an error the MirrorPrintStream will be flagged as having an error. By default bytes will be written to the beginning of the file- Parameters:
fileName
- The name of the file to direct output.- See Also:
mirrorToFile(String, boolean)
-
mirrorToFile
public void mirrorToFile(java.lang.String fileName, boolean append)
Enable mirroring to the given file. If there is an error the MirrorPrintStream will be flagged as having an error.- Parameters:
fileName
- The name of the file to direct output.append
- if true, then bytes will be written to the end of the file rather than the beginning
-
disableMirror
public void disableMirror()
Disable the mirror operation.
-
setError
protected void setError()
Sets the error state of the stream totrue
.This method will cause subsequent invocations of
checkError()
to return true untilclearError()
is invoked.- Overrides:
setError
in classjava.io.PrintStream
-
clearError
protected void clearError()
Clears the internal error state of this stream.This method will cause subsequent invocations of
checkError()
to return false until another write operation fails and invokessetError()
.- Overrides:
clearError
in classjava.io.PrintStream
-
-