Package eu.bandm.tools.message
Class MessagePrinter<M extends Message>
java.lang.Object
eu.bandm.tools.message.MessagePrinter<M>
- All Implemented Interfaces:
MessageReceiver<M>
- Direct Known Subclasses:
MessagePrinter.Indenting
Prints textual representations of all received messages to an
output stream.
After each printed message this stream is
After each printed message this stream is
flushed
explicitly.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
MessagePrinter.Indenting<M extends Message>
Specialization ofMessagePrinter
with addtional features. -
Field Summary
-
Constructor Summary
ConstructorDescriptionPrints toSystem.err
, using default encoding.Creates and uses as its drain a freshPrintWriter
to theOutputStream
argument. -
Method Summary
Modifier and TypeMethodDescriptionvoid
setMessageToString
(Function<? super M, ? extends String> toStr) Sets the function which converts the message to a printable string.
-
Field Details
-
out
The drain of the print activities. -
toStr
The function which converts the message to a printable string. Defaults toObject::toString
.
-
-
Constructor Details
-
MessagePrinter
public MessagePrinter()Prints toSystem.err
, using default encoding. -
MessagePrinter
Creates and uses as its drain a freshPrintWriter
to theOutputStream
argument.
Therefore printing must use the default character encoding. -
MessagePrinter
-
-
Method Details
-
setMessageToString
Sets the function which converts the message to a printable string. -
receive
Print the message to the output stream.
Rendering is done by applying the function intoStr
.
After each printed message the output stream isflushed
explicitly.- Specified by:
receive
in interfaceMessageReceiver<M extends Message>
-