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

public class MirrorPrintStream extends 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 Details

    • fileStream

      protected PrintStream fileStream
      The file stream.
    • fileName

      protected String fileName
      The file name.
  • Constructor Details

    • MirrorPrintStream

      public MirrorPrintStream(OutputStream os, boolean flush)
    • MirrorPrintStream

      public MirrorPrintStream(OutputStream os)
      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 class PrintStream
    • write

      public void write(int x)
      Overrides:
      write in class PrintStream
    • write

      public void write(byte[] x, int o, int l)
      Overrides:
      write in class PrintStream
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class PrintStream
    • flush

      public void flush()
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class PrintStream
    • mirrorToFile

      public void mirrorToFile(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

      public void mirrorToFile(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 to true.

      This method will cause subsequent invocations of checkError() to return true until clearError() is invoked.

      Overrides:
      setError in class 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 invokes setError().

      Overrides:
      clearError in class PrintStream