Class MirrorPrintStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
org.eclipse.epsilon.common.dt.console.MirrorPrintStream
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
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
FieldsModifier and TypeFieldDescriptionprotected String
The file name.protected PrintStream
The file stream.Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a MirrorPrintStream with autoflush.MirrorPrintStream
(OutputStream os, boolean flush) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true if either stream has an error.protected void
Clears the internal error state of this stream.void
close()
void
Disable the mirror operation.void
flush()
void
mirrorToFile
(String fileName) Enable mirroring to the given file.void
mirrorToFile
(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) Methods inherited from class java.io.PrintStream
append, append, append, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, write, writeBytes
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
fileStream
The file stream. -
fileName
The file name.
-
-
Constructor Details
-
MirrorPrintStream
-
MirrorPrintStream
Instantiates a MirrorPrintStream with autoflush.- Parameters:
os
- the os
-
-
Method Details
-
checkError
public boolean checkError()Return true if either stream has an error.- Overrides:
checkError
in classPrintStream
-
write
public void write(int x) - Overrides:
write
in classPrintStream
-
write
public void write(byte[] x, int o, int l) - Overrides:
write
in classPrintStream
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classPrintStream
-
flush
public void flush()- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classPrintStream
-
mirrorToFile
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
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 classPrintStream
-
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 classPrintStream
-