Class OffsetIndicationPrinter

java.lang.Object
eu.bandm.tools.message.OffsetIndicationPrinter
All Implemented Interfaces:
MessageReceiver<SimpleMessage<String>>

public class OffsetIndicationPrinter extends Object implements MessageReceiver<SimpleMessage<String>>
Prints textual representations of all receiv1ed messages to an output stream.

Assumes that the DocumentId is the one line document contents (i.e. a string contents which is its own identifier), and indicates the error position by indentation in a second line below the printed contents.

  • Field Details

    • out

      protected final PrintWriter out
      The target of all print activities.
    • prependNewline

      protected boolean prependNewline
      Whether to emit a leading newline, Can be set by class derivation
        new OffsetIndicationPrinter(){{prependNewline=true;}}
        
  • Constructor Details

    • OffsetIndicationPrinter

      public OffsetIndicationPrinter()
      Prints to System.err, using default encoding.
    • OffsetIndicationPrinter

      public OffsetIndicationPrinter(OutputStream os)
      Prints to a newly created PrintWriter to the OutputStream provided.
      Consequently using a default encoding.
    • OffsetIndicationPrinter

      public OffsetIndicationPrinter(PrintWriter out)
      Prints to thre PrintWriter provided.

      So the encoding can be set explicitly.
  • Method Details

    • receive

      public void receive(SimpleMessage<String> message)
      Print the message to the output stream.

      First the id is printed (= the document contents), then a newline, an indentation, a caret symbol, the message kind and the message text. After each printed message the output stream is flushed explicitly.
      In situations where stderr is likely to be contaminated with other output, not terminated by newline, an extra newline can be prepended to make the indentation correct.
      Specified by:
      receive in interface MessageReceiver<SimpleMessage<String>>