Class Outstream2Log<D>

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
eu.bandm.tools.message.Outstream2Log<D>
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class Outstream2Log<D> extends FilterOutputStream
Pipes every printed line (on its completion) into one "log" message sent to the message receiver. Usage: construct an instance with the drain and write to the PrintStream which is offered by printStream(). A Location may be set for the very next generated log message by sendLoc(Location).
  • Field Details

  • Constructor Details

  • Method Details

    • printStream

      public PrintStream printStream()
      Deliver the stream to which the user can print. It is set to "autoflush", so that messages are generated early, when writing newlines, etc., see PrintStream(java.io.OutputStream,boolean).
    • withKind

      public Outstream2Log<D> withKind(Message.Kind kind)
      Set the message kind. Hint and Log are sensible.
    • sendLoc

      public void sendLoc(@Opt @Opt Location<D> loc)
      Set the location for the very next message synthesized. After that, it will be reset to null.
    • write

      public void write(byte[] c, int a, int b)
      Write bytes into internal buffer, until a flush() is executed.
      Overrides:
      write in class FilterOutputStream
    • flush

      public void flush()
      Flush the buffer to the message drain.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class FilterOutputStream
    • doFlush

      protected void doFlush(boolean isFinal)
      Split the (trimmed) text content written after the last call (or construction) into lines and wrap each of these into a log message. The first gets the location info. If there are characters after the last linefeed, they are sent also iff final=true, otherwise re-written into the cleared buffer for the next call to this method.
      Parameters:
      isFinal - whether this call comes from a (final) call to close().
    • close

      public void close()
      Flush the buffer to the message drain completely, even when not terminated with a linefeed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterOutputStream