|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfeud.clientserver.DataContainer
DataContainers are the basic transfer containers for data in this little client/server-world. Each transfer from or to
a server or a client will most likely contain at least one DataContainer dropped into an array of DataContainers which itself will be wrapped into an array of bytes.
A transfer can contain multiple DataContainers of different types. What's stored into these containers is up to the implementation.
One can easily extend the DataContainer to wrap complex data in a convenient way.
Field Summary | |
protected ClientInfo |
ci
|
protected int |
msgType
|
protected java.util.List |
objs
|
protected int |
pos
|
static byte |
TYPE_BYTE
|
static byte |
TYPE_FLOAT
|
static byte |
TYPE_INT
|
static byte |
TYPE_STRING
|
protected java.util.List |
types
|
Constructor Summary | |
DataContainer()
Creates a new, empty DataContainer. |
|
DataContainer(byte[] bytes)
Creates a new DataContainer and populates it with the data wrapped in the given byte arrays. |
|
DataContainer(byte[] bytes,
boolean zip)
Creates a new DataContainer and populates it with the data wrapped in the given byte arrays. |
Method Summary | |
void |
add(byte byt)
Adds a new byte to the container. |
void |
add(float flt)
Adds a new float to the container. |
void |
add(int in)
Adds a new int to the container. |
void |
add(java.lang.String str)
Adds a new String to the container. |
java.lang.Object |
clone()
|
int |
getBufferLength()
Returns the number of entries in this container |
ClientInfo |
getClientInfo()
Returns the ClientInfo, the info about the client from which this container came. |
int |
getLength()
Returns the length of the byte array from which this container has been created. |
int |
getMessageType()
Gets the message type of this container as defined by MessageTypes. |
byte |
getNextByte()
Reads the next byte from the container. |
float |
getNextFloat()
Reads the next float from the container. |
int |
getNextInt()
Reads the next int from the container. |
java.lang.String |
getNextString()
Reads the next string from the container. |
byte[] |
getRawData()
Returns the raw data (after unzipping) if this DataContainer has been created from a byte array. |
byte |
getType()
Returns the type of the next entry in the container. |
(package private) boolean |
getZip()
Gets the zip mode of this container |
boolean |
hasData()
Checks, if the container contains more data to read. |
void |
reset()
Clears the container. |
void |
setClientInfo(ClientInfo c)
Sets the ClientInfo, the info about the client from which this container came. |
void |
setMessageType(int type)
Sets the message type of this container as defined by MessageTypes. |
(package private) void |
setZip(boolean zip)
Sets zip mode for this container |
DataContainer |
skip()
Skips an entry in the container. |
(package private) byte[] |
toByteArray(boolean zip)
Wraps the container's data into a byte array. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final byte TYPE_INT
public static final byte TYPE_FLOAT
public static final byte TYPE_STRING
public static final byte TYPE_BYTE
protected java.util.List objs
protected java.util.List types
protected int pos
protected ClientInfo ci
protected int msgType
Constructor Detail |
public DataContainer()
public DataContainer(byte[] bytes)
bytes
- the data for this containerpublic DataContainer(byte[] bytes, boolean zip)
bytes
- the data for this containerzip
- is the data in this array zipped?Method Detail |
public int getLength()
public int getBufferLength()
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException
public byte[] getRawData()
public void setClientInfo(ClientInfo c)
c
- the client infopublic ClientInfo getClientInfo()
public int getMessageType()
public void setMessageType(int type)
type
- the message typepublic void add(float flt)
flt
- a floatpublic void add(int in)
in
- a intpublic void add(byte byt)
byt
- a bytepublic void add(java.lang.String str)
str
- a Stringpublic void reset()
public boolean hasData()
public DataContainer skip()
public byte getType()
public float getNextFloat()
public int getNextInt()
public byte getNextByte()
public java.lang.String getNextString()
byte[] toByteArray(boolean zip)
zip
- boolean
void setZip(boolean zip)
zip
- zipped?boolean getZip()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |