public abstract class Formatter extends Object
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 and Description |
|---|
Formatter() |
| Modifier and Type | Method and Description |
|---|---|
abstract int |
compile(Packet packet)
Preprocesses (or compiles) a packet and returns the required size for the compiled
result.
|
void |
format(Packet packet,
OutputStream stream)
Compiles a packet and writes it to a stream.
|
abstract void |
write(OutputStream stream)
Writes a previously compiled packet to the supplied stream.
|
public abstract int compile(Packet packet) throws IOException
packet - The packet to compileIOException - io exceptionpublic abstract void write(OutputStream stream) throws IOException
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.
stream - The stream to write the packet to.IOException - If an I/O error occurred while trying to write the
compiled packet.public void format(Packet packet, OutputStream stream) throws IOException
This non-abstract method simply calls the compile method with the supplied packet object and then the write method with the supplied stream object.
packet - The packet to compile.stream - The stream to write the packet to.IOException - If an I/O error occurred while trying
to write the compiled packet.Copyright © 2023. All rights reserved.