|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--amber.type.Packet
This class handles the actual packet processing required to message between the client and server parts of the amber system.
| Field Summary | |
static int |
Command
The type of command to perform or event to process. |
static int |
CommandNone
This is the basic command. |
protected byte[] |
data
This is the actual data held in the packet. |
static int |
DataLengthStart
This is the length of the data following the header if any. |
static int |
DestinationIdHigh
This is the id to send the packet to. |
static int |
DestinationIdLow
This is the id to send the packet to. |
static int |
EventFlag
This is a flag indicating that the packet is an event rather than a command. |
static int |
Flags
These are various flags which affect the processing of the header and data. |
protected byte[] |
header
This is the actual header information of the packet. |
static int |
IncompleteFlag
This is a flag indicating that there are more packets to follow before the sequence is complete. |
static int |
MagicMarker
This is the magic marker start of the packet. |
static int |
PacketHeaderLength
This is the length of the header in the packet. |
static byte |
PacketMagicMarker
This is magic character which flags the beginning of the packet. |
static short |
ServerId
This is the ID given to the remote server. |
static int |
SourceIdHigh
This is the id of the applet which sent the packet. |
static int |
SourceIdLow
This is the id of the applet which sent the packet. |
static int |
Version
This is the version of the packet. |
| Constructor Summary | |
Packet()
Default Constructor. |
|
Packet(byte version,
byte flags,
byte command,
short destinationId,
short sourceId,
int dataLength,
byte[] data,
boolean event)
Initialising Constructor. |
|
Packet(byte command,
short destinationId,
short sourceId,
boolean event)
Initialising Constructor. |
|
Packet(byte command,
short destinationId,
short sourceId,
int dataLength,
byte[] data,
boolean event)
Initialising Constructor. |
|
Packet(java.io.InputStream input)
Constructor used when filling the packet from an input stream. |
|
| Method Summary | |
static int |
bytesToInt(byte[] value,
int offset)
|
static short |
bytesToShort(byte[] data,
int offset)
|
boolean |
compareTo(byte[] otherHeader)
This function compares the packets header to the input byte array. |
byte |
getCommand()
Gets the data in the following variable: The type of command to perform or event to process. |
byte[] |
getData()
Gets the data in the following variable: This is the actual data itself following the header if any. |
int |
getDataLength()
Gets the data in the following variable: This is the length of the data following the header if any. |
short |
getDestinationId()
Gets the data in the following variable: This is the id to send the packet to. |
byte |
getFlags()
Gets the data in the following variable: These are various flags which affect the processing of the header and data. |
byte[] |
getHeader()
Returns the header array. |
short |
getSourceId()
Gets the data in the following variable: This is the id of the applet which sent the packet. |
byte |
getVersion()
Gets the data in the following variable: This is the version of the packet. |
boolean |
headerOnlyComparesTo(byte[] otherHeader)
This function compares the packets header to the input byte array. |
static void |
intToBytes(int value,
byte[] data,
int offset)
|
boolean |
isEvent()
Returns true if this packet is an event. |
boolean |
isIncomplete()
Returns true if this packet is part of an incomplete packet sequence. |
void |
readPacket(java.io.InputStream input)
Reads in a packet from the specified input stream. |
void |
sendPacket(java.io.OutputStream output)
Writes a packet to the specified output stream. |
void |
setCommand(byte data)
Sets the data in the following variable: The type of command to perform or event to process. |
void |
setData(byte[] data)
Sets the data in the following variable: This is the actual data in the packet if any. |
void |
setDataLength(int data)
Sets the data in the following variable: This is the length of the data following the header if any. |
void |
setDestinationId(short data)
Sets the data in the following variable: This is the id to send the packet to. |
void |
setEvent(boolean eventFlag)
Sets the event flag in the packet. |
void |
setFlags(byte data)
Sets the data in the following variable: These are various flags which affect the processing of the header and data. |
void |
setIncomplete(boolean incompleteFlag)
Sets the incomplete packet sequence flag in the packet. |
void |
setSourceId(short data)
Sets the data in the following variable: This is the id of the applet which sent the packet. |
void |
setVersion(byte data)
Sets the data in the following variable: This is the version of the packet. |
static byte[] |
shortToBytes(short value)
|
static void |
shortToBytes(short value,
byte[] data,
int offset)
|
java.lang.String |
toString()
This function returns the String form of the data. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int PacketHeaderLength
public static final byte PacketMagicMarker
public static final int CommandNone
public static final short ServerId
public static final int MagicMarker
public static final int Version
public static final int Flags
public static final int Command
public static final int DestinationIdHigh
public static final int DestinationIdLow
public static final int SourceIdHigh
public static final int SourceIdLow
public static final int DataLengthStart
public static final int EventFlag
public static final int IncompleteFlag
protected byte[] header
protected byte[] data
| Constructor Detail |
public Packet()
public Packet(byte command,
short destinationId,
short sourceId,
boolean event)
command - The type of command to perform or event to process.destinationId - This is the id to send the packet to.sourceId - This is the id of the applet which sent the packet.event - boolean true when this packet is an event.
public Packet(byte command,
short destinationId,
short sourceId,
int dataLength,
byte[] data,
boolean event)
command - The type of command to perform or event to process.destinationId - This is the id to send the packet to.sourceId - This is the id of the applet which sent the packet.dataLength - This is the length of the data following the header if any.data - This is the data for the packet stored in a byte array.event - boolean true when this packet is an event.
public Packet(byte version,
byte flags,
byte command,
short destinationId,
short sourceId,
int dataLength,
byte[] data,
boolean event)
version - This is the version of the packet.flags - These are various flags which affect the processing of the header and data.command - The type of command to perform or event to process.destinationId - This is the id to send the packet to.sourceId - This is the id of the applet which sent the packet.dataLength - This is the length of the data following the header if any.data - This is the data for the packet stored in a byte array.
public Packet(java.io.InputStream input)
throws java.io.IOException,
java.net.ProtocolException
| Method Detail |
public byte getVersion()
public byte getFlags()
public byte getCommand()
public short getDestinationId()
public short getSourceId()
public int getDataLength()
public byte[] getData()
public void setVersion(byte data)
data - byte containing the data to set the variable to.public void setFlags(byte data)
data - byte containing the data to set the variable to.public void setCommand(byte data)
data - byte containing the data to set the variable to.public void setDestinationId(short data)
data - byte containing the data to set the variable to.public void setSourceId(short data)
data - byte containing the data to set the variable to.public void setDataLength(int data)
data - int containing the data to set the variable to.public void setData(byte[] data)
data - byte [] containing the data to set the variable to.
public void readPacket(java.io.InputStream input)
throws java.io.IOException,
java.net.ProtocolException
input - InputStream from which the packet will be read.java.net.ProtocolException. - This exception contains the error in the packet.java.io.IOException. - This exception contains the error in the IO stream.
public void sendPacket(java.io.OutputStream output)
throws java.io.IOException,
java.net.ProtocolException
output - OutputStream to which the packet will be written.java.net.ProtocolException. - This exception contains the error in the packet.java.io.IOException. - This exception contains the error in the IO stream.public java.lang.String toString()
toString in class java.lang.Object
public static void intToBytes(int value,
byte[] data,
int offset)
public static int bytesToInt(byte[] value,
int offset)
public static short bytesToShort(byte[] data,
int offset)
public static void shortToBytes(short value,
byte[] data,
int offset)
public static byte[] shortToBytes(short value)
public void setEvent(boolean eventFlag)
eventFlag - boolean true if this packet is an event.public boolean isEvent()
public void setIncomplete(boolean incompleteFlag)
incompleteFlag - boolean true if this packet is an incomplete sequence.public boolean isIncomplete()
public byte[] getHeader()
public boolean compareTo(byte[] otherHeader)
otherHeader - byte [] containing the other packet header to match.public boolean headerOnlyComparesTo(byte[] otherHeader)
otherHeader - byte [] containing the other packet header to match.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||