Class TextFormatter


  • public class TextFormatter
    extends Formatter
    Responsible for creating a text representation of a packet and writing it to a stream.

    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 Detail

      • TextFormatter

        public TextFormatter()
        Creates and initializes a TextFormatter instance.
    • Method Detail

      • compile

        public int compile​(Packet packet)
                    throws IOException
        Overridden. Preprocesses (or compiles) a packet and returns the required size for the compiled result.

        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.

        Specified by:
        compile in class Formatter
        Parameters:
        packet - The packet to compile
        Returns:
        The size for the compiled result
        Throws:
        IOException - io exception
      • write

        public void write​(OutputStream stream)
                   throws IOException
        Overridden. Writes a previously compiled packet to the supplied stream.

        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.

        Specified by:
        write in class Formatter
        Parameters:
        stream - The stream to write the packet to
        Throws:
        IOException - if an I/O error occurred while trying to write the compiled packet
      • getPattern

        public String getPattern()
        Returns the pattern used to create a text representation of a packet.

        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.

        Returns:
        The pattern string
      • setPattern

        public void setPattern​(String pattern)
        Sets the pattern used to create a text representation of a packet. 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.
        Parameters:
        pattern - The new pattern string
      • getIndent

        public boolean getIndent()
        Returns if this formatter automatically intends log packets like in the Views of the SmartInspect Console.

        Log Entry packets of type EnterMethod increase the indentation and packets of type LeaveMethod decrease it.

        Returns:
        True if this formatter automatically intends log packets and false otherwise
      • setIndent

        public void setIndent​(boolean indent)
        Sets if this formatter automatically indents log packets like in the views of the SmartInspect Console.

        Log Entry packets of type EnterMethod increase the indentation and packets of type LeaveMethod decrease it.

        Parameters:
        indent - Should be true if this formatter should automatically indent log packets and false otherwise