|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface PacketWriter
Interface for classes implementing packet writing strategies.
The method setPacket(byte[]) initializes for writer for output of a new
packet. Implementing classes can assume that setPacket is never called unless
isEmpty()
returns true. The getBuffer()
method should return a ByteBuffer containing
the next chunk of data to output on the socket.
The implementation is similar to:
while (!packetWriter.isEmpty()) channel.write(packetWriter.getBuffer());
In other words, it is ok to split a single packet into several byte buffers each are handed in
turn for every call to getBuffer(). (See RegularPacketWriter source code for an example.)
| Method Summary | |
|---|---|
java.nio.ByteBuffer |
getBuffer()
The current byte buffer to write to the socket. |
boolean |
isEmpty()
Determines if the packet writer has more data to write. |
void |
setPacket(byte[] bytes)
Set the next packet to write. |
| Method Detail |
|---|
void setPacket(byte[] bytes)
bytes - an array of bytes representing the next packet.boolean isEmpty()
Classes will never invoke setPacket(byte[]) unless
isEmpty returns true.
java.nio.ByteBuffer getBuffer()
Note that the socket does no rewinding or similar of the buffer,
the only way it interacts with the buffer is by calling
SocketChannel.write(ByteBuffer), so the implementing
class needs to make sure that the buffer is in the right state.
This code will not be called unless isEmpty() returns false.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||