|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteap.freeciv.PacketSource
Allows you to read packets from an InputStream.
All of the Field
objects read their data from a PacketSource.
Constructor Summary | |
PacketSource(InputStream in)
Creates a new packet source which will use a default packet broker. |
|
PacketSource(InputStream in,
PacketBroker broker)
Creates a new packet source which will read from the given underlying stream and use the given packet broker to determine the structure of each packet. |
Method Summary | |
int |
readByte()
Reads the next byte in the packet. |
void |
readBytes(byte[] data)
Fill a byte array by reading from the stream. |
Packet |
readPacket()
Reads the next packet from the data stream. |
int |
remainingBytes()
Returns the number of unread bytes in the current packet, according to the size field in the packet header. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PacketSource(InputStream in, PacketBroker broker)
public PacketSource(InputStream in)
Method Detail |
public int remainingBytes()
public Packet readPacket() throws IOException
Currently, this method checks each packet for validity by saving the packet bytes verbatim from the stream, and then writing the packet to a byte array and comparing the two. If they are different, it prints an error message to stderr and exits. You can turn this off by setting CHECK_PACKETS and recompiling.
EOFException
- if the underlying stream reached EOF in the middle of
the packet.
IOException
- if the data did not conform to the proper structure,
such as if the actual packet size was different from the size in the
packet header. I should really create a new exception for Packet
structure problems, but for now it was easier to use IOException
for everything.public int readByte() throws IOException
Field
classes use
this method or readBytes(byte[])
to read from the underlying stream.
These methods keep track of the "bytes reamining" accounting.
This method blocks until the next byte is available.
IOException
- if you try to read past the end of the current packet
EOFException
- if you try to read when you are at EOF.public void readBytes(byte[] data) throws IOException
IOException
- if you try to read past the end of the current packet
EOFException
- if you reach EOF.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |