public class TextFormatter extends Formatter
This class creates a text representation of a packet and writes it to a stream. The representation can be influenced with the setPattern method. The compile method preprocesses a packet and computes the required size of the packet. The write method writes the preprocessed packet to the supplied stream.
Note: This class is not guaranteed to be threadsafe.
| Constructor and Description |
|---|
TextFormatter()
Creates and initializes a TextFormatter instance.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compile(Packet packet)
Overridden.
|
boolean |
getIndent()
Returns if this formatter automatically intends log packets like
in the Views of the SmartInspect Console.
|
String |
getPattern()
Returns the pattern used to create a text representation of a packet.
|
void |
setIndent(boolean indent)
Sets if this formatter automatically indents log packets like in
the views of the SmartInspect Console.
|
void |
setPattern(String pattern)
Sets the pattern used to create a text representation of a
packet.
|
void |
write(OutputStream stream)
Overridden.
|
public TextFormatter()
public int compile(Packet packet) throws IOException
This method creates a text representation of the supplied packet and computes the required size. The resulting representation can be influenced with the setPattern method. To write a compiled packet, call the write method. Please note that this method only supports LogEntry objects and ignores any other packet. This means, for packets other than LogEntry, this method always returns 0.
compile in class Formatterpacket - The packet to compileIOException - io exceptionpublic void write(OutputStream stream) throws IOException
This method writes the previously computed text representation of a packet (see compile) to the supplied stream object. If the return value of the compile method was 0, nothing is written.
write in class Formatterstream - The stream to write the packet toIOException - if an I/O error occurred while trying to write the compiled packetpublic String getPattern()
For detailed information of how a pattern string can look like, please have a look at the documentation of the PatternParser class, especially the PatternParser.setPattern method.
public void setPattern(String pattern)
pattern - The new pattern stringpublic boolean getIndent()
Log Entry packets of type EnterMethod increase the indentation and packets of type LeaveMethod decrease it.
public void setIndent(boolean indent)
Log Entry packets of type EnterMethod increase the indentation and packets of type LeaveMethod decrease it.
indent - Should be true if this formatter should automatically indent log
packets and false otherwiseCopyright © 2023. All rights reserved.