|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpeerbase.PeerMessage
public class PeerMessage
Represents a message, composed of type and data fields, in the PeerBase system. Also provides functionality for converting messages to/from byte arrays in a portable manner. The type of every message is a 4-byte value (i.e. 4-character string).
Constructor Summary | |
---|---|
PeerMessage(byte[] type,
byte[] data)
Constructs a new PeerMessage object. |
|
PeerMessage(SocketInterface s)
Constructs a new PeerMessage object by reading data from the given socket connection. |
|
PeerMessage(java.lang.String type,
byte[] data)
Constructs a new PeerMessage object. |
|
PeerMessage(java.lang.String type,
java.lang.String data)
Constructs a new PeerMessage object. |
Method Summary | |
---|---|
static int |
byteArrayToInt(byte[] byteArray)
|
java.lang.String |
getMsgData()
Returns the message data as a String. |
byte[] |
getMsgDataBytes()
Returns the message data. |
java.lang.String |
getMsgType()
Returns the message type as a String. |
byte[] |
getMsgTypeBytes()
Returns the message type. |
static byte[] |
intToByteArray(int integer)
Returns a byte array containing the two's-complement representation of the integer. The byte array will be in big-endian byte-order with a fixes length of 4 (the least significant byte is in the 4th element). Example: intToByteArray(258) will return { 0, 0, 1, 2 },BigInteger.valueOf(258).toByteArray() returns { 1, 2 }. |
byte[] |
toBytes()
Returns a packed representation of this message as an array of bytes. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PeerMessage(byte[] type, byte[] data)
type
- the message type (4 bytes)data
- the message datapublic PeerMessage(java.lang.String type, java.lang.String data)
type
- the message type (4 characters)data
- the message datapublic PeerMessage(java.lang.String type, byte[] data)
type
- the message type (4 characters)data
- the message datapublic PeerMessage(SocketInterface s) throws java.io.IOException
s
- a socket connection object
java.io.IOException
- if I/O error occursMethod Detail |
---|
public java.lang.String getMsgType()
public byte[] getMsgTypeBytes()
public java.lang.String getMsgData()
public byte[] getMsgDataBytes()
public byte[] toBytes()
public java.lang.String toString()
toString
in class java.lang.Object
public static byte[] intToByteArray(int integer)
intToByteArray(258)
will return { 0, 0, 1, 2 },BigInteger.valueOf(258).toByteArray()
returns { 1, 2 }.
integer
- The integer to be converted.
public static int byteArrayToInt(byte[] byteArray)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |