Package eu.bandm.tools.message
Class Outstream2Log<D>
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
eu.bandm.tools.message.Outstream2Log<D>
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
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)
.
ATTENTION normally the drain for the messaage should NOT
employ a MessageFormatter
or a
MessageTranslator
.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ByteArrayOutputStream
Auxiliary target of the print actions.(package private) Message.Kind
Kind of generated messages.Intermediate storage for the location of the next message.protected final MessageReceiver<SimpleMessage<D>>
Where to send the message.Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorDescriptionOutstream2Log
(MessageReceiver<SimpleMessage<D>> drain) Constructor specifying (finally) the receiver.Outstream2Log
(MessageReceiver<SimpleMessage<D>> drain, @Opt Location<D> loc) Constructor specifying (finally) the receiver and the first location. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Flush the buffer to the message drain completely, even when not terminated with a linefeed.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.void
flush()
Flush the buffer to the message drain.Deliver the stream to which the user can print.void
Set the location for the very next message synthesized.withKind
(Message.Kind kind) Set the message kind.void
write
(byte[] c, int a, int b) Write bytes into internal buffer, until a flush() is executed.Methods inherited from class java.io.FilterOutputStream
write, write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
bos
Auxiliary target of the print actions. -
receiver
Where to send the message. -
loc
Intermediate storage for the location of the next message. -
kind
Message.Kind kindKind of generated messages. Logg and Hint are sensible values.
-
-
Constructor Details
-
Outstream2Log
Constructor specifying (finally) the receiver. -
Outstream2Log
Constructor specifying (finally) the receiver and the first location.
-
-
Method Details
-
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., seePrintStream(java.io.OutputStream,boolean)
. -
withKind
Set the message kind. Hint and Log are sensible. -
sendLoc
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 classFilterOutputStream
-
flush
public void flush()Flush the buffer to the message drain.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterOutputStream
-
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 toclose()
.
-
close
public void close()Flush the buffer to the message drain completely, even when not terminated with a linefeed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
-