Class TextFileOutput

Object
TextFileOutput

public class TextFileOutput extends Object
Utility for writing to a text-file at a particular path, but only if it is enabled.

If a file is disabled, the methods can be called as normal, but no text-file is creates and no content is written.

To write contents, a sequence should be followed:

  1. Call start().
  2. Call methods on getWriter() to write content.
  3. Call end().
Author:
Owen Feehan
  • Constructor Details

    • TextFileOutput

      public TextFileOutput(String filePath)
      Creates a new TextFileOutput instance.
      Parameters:
      filePath - The path to which the text-file is written.
  • Method Details

    • start

      public void start() throws OutputWriteFailedException
      This should be called once before subsequently writing content with getWriter()
      Throws:
      OutputWriteFailedException - if unable to write content to filePath.
    • isEnabled

      public boolean isEnabled()
      Whether the writer is enabled to write to the file-system.
      Returns:
      true iff the writer is enabled, otherwise it is disabled and no content is written.
    • end

      public void end()
      This should be called once after writing all content with getWriter()
    • getWriter

      public Optional<PrintWriter> getWriter()
      The PrintWriter used for writing the text file.