Class Formatter
- java.lang.Object
-
- com.gurock.smartinspect.formatters.Formatter
-
- Direct Known Subclasses:
BinaryFormatter,TextFormatter
public abstract class Formatter extends Object
Responsible for formatting and writing a packet.This abstract class defines several methods which are intended to preprocess a packet and subsequently write it to a stream. The process of preprocessing (or compiling) and writing a packet can either be executed with a single step by calling the format method or with two steps by calls to compile and write.
Note: This class and subclasses thereof are not guaranteed to be threadsafe.
-
-
Constructor Summary
Constructors Constructor Description Formatter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intcompile(Packet packet)Preprocesses (or compiles) a packet and returns the required size for the compiled result.voidformat(Packet packet, OutputStream stream)Compiles a packet and writes it to a stream.abstract voidwrite(OutputStream stream)Writes a previously compiled packet to the supplied stream.
-
-
-
Method Detail
-
compile
public abstract int compile(Packet packet) throws IOException
Preprocesses (or compiles) a packet and returns the required size for the compiled result. To write a previously compiled packet, call the write method. Derived classes are intended to compile the supplied packet and return the required size for the compiled result.- Parameters:
packet- The packet to compile- Returns:
- The size for the compiled result
- Throws:
IOException- io exception
-
write
public abstract void write(OutputStream stream) throws IOException
Writes a previously compiled packet to the supplied stream.This method is intended to write a previously compiled packet (see compile) to the supplied stream object. If the return value of the compile method was 0, nothing is written.
- Parameters:
stream- The stream to write the packet to.- Throws:
IOException- If an I/O error occurred while trying to write the compiled packet.
-
format
public void format(Packet packet, OutputStream stream) throws IOException
Compiles a packet and writes it to a stream.This non-abstract method simply calls the compile method with the supplied packet object and then the write method with the supplied stream object.
- Parameters:
packet- The packet to compile.stream- The stream to write the packet to.- Throws:
IOException- If an I/O error occurred while trying to write the compiled packet.
-
-