Class BinaryFormatter


  • public class BinaryFormatter
    extends Formatter
    Responsible for formatting and writing a packet in the standard SmartInspect binary format.

    This class formats and writes a packet in the standard binary format which can be read by the SmartInspect Console. 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.

    This class is not guaranteed to be threadsafe.

    • Constructor Detail

      • BinaryFormatter

        public BinaryFormatter()
        Creates and initializes a BinaryFormatter 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 preprocesses the supplied packet and computes the required binary format size. To write this compiled packet, call the write method.

        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 compiled 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 - An I/O error occurred while trying to write the compiled packet.