Class StreamTarget

All Implemented Interfaces:
ErrorAware, LogTarget, Closeable
Direct Known Subclasses:
FileTarget

public class StreamTarget extends AbstractOutputTarget
A basic target that writes to an OutputStream.
Author:
Peter Donald
  • Field Details

    • m_outputStream

      private OutputStream m_outputStream
      OutputStream we are writing to.
    • m_encoding

      private String m_encoding
      The encoding to use when creating byte array for string, may be null.
  • Constructor Details

    • StreamTarget

      public StreamTarget(OutputStream outputStream, Formatter formatter, String encoding)
      Constructor that writes to a stream and uses a particular formatter.
      Parameters:
      outputStream - the OutputStream to write to
      formatter - the Formatter to use
      encoding - Desired encoding to use when writing to the log, null implies the default system encoding.
    • StreamTarget

      public StreamTarget(OutputStream outputStream, Formatter formatter)
      Constructor that writes to a stream and uses a particular formatter.
      Parameters:
      outputStream - the OutputStream to write to
      formatter - the Formatter to use
  • Method Details

    • setOutputStream

      protected void setOutputStream(OutputStream outputStream)
      Set the output stream. Close down old stream and write tail if appropriate.
      Parameters:
      outputStream - the new OutputStream
    • write

      protected void write(String data)
      Abstract method that will output event.
      Overrides:
      write in class AbstractOutputTarget
      Parameters:
      data - the data to be output
    • close

      public void close()
      Shutdown target. Attempting to write to target after close() will cause errors to be logged.
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AbstractOutputTarget
    • shutdownStream

      protected void shutdownStream()
      Shutdown output stream.