Package eu.bandm.tools.message
Class Outstream2Log<D>
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
eu.bandm.tools.message.Outstream2Log<D>
- Type Parameters:
D
- the type of the document identifier
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Wraps every printed line (on its completion) into one "log" message
and sends it 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)
.
(When the pipeline serving as drain
contains a MessageFormatter
or another specialized
processor, care must be taken what contents to print.)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ByteArrayOutputStream
Auxiliary target of the print actions.(package private) Message.Kind
Kind of generated messages.protected int
The level with which all messages will be encoded.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
ConstructorsConstructorDescriptionOutstream2Log
(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 text content written since last invocation (or since construction) into lines and wrap each of these into a message.void
flush()
Flush the buffer to the message drain.Deliver the stream to which the user can print.Set the location for the very next message synthesized.withKind
(Message.Kind kind) Set the message kind.withLevel
(int level) Set the message level.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
-
level
protected int levelThe level with which all messages will be encoded. -
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.- Parameters:
drain
- where to send the messages
-
Outstream2Log
Constructor specifying (finally) the receiver and the first location.- Parameters:
drain
- where to send the messagesloc
- the start location
-
-
Method Details
-
printStream
Deliver the stream to which the user can print. It is set to "autoflush=true", so that messages are generated early, when writing newlines, etc., seePrintStream(java.io.OutputStream,boolean)
.- Returns:
- the stream to which the user can print.
-
withKind
Set the message kind. Hint and Log are usual values.- Parameters:
kind
- the kind of the generated messages- Returns:
- this instance (for method chaining)
-
withLevel
Set the message level.- Parameters:
level
- to be used with the following messages- Returns:
- this instance (for method chaining)
-
sendLoc
Set the location for the very next message synthesized. After that, it will be reset to null.- Parameters:
loc
- the location for the very next message synthesized.- Returns:
- this instance (for method chaining)
-
write
public void write(byte[] c, int a, int b) Write bytes into internal buffer, until a flush() is executed.- Overrides:
write
in classFilterOutputStream
- See Also:
-
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 text content written since last invocation (or since construction) into lines and wrap each of these into a message. The first gets the location info.If there are characters after the last linefeed, they are sent also iff final=true, otherwise they are memorized for the next invocation of this method.
- Parameters:
isFinal
- whether this call comes from a 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
-