|
|||||||||
| Home >> All >> java >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.net
Class ZObject

java.lang.Objectjava.net.ZObject
- public class ZObject
- extends java.lang.Object
This class implements an object type suitable to be serialized in a non-standard way. To minimize the overhead that can occur in standard serialization, this class provides methods to serialize and deserialize objects minimizing the overhead. This class can represents compressed, uncompressed and ack objects.
- Version:
- 1.0
| Field Summary | |
static byte |
ACK_TYPE
|
static byte |
COMPR_TYPE
|
protected byte[] |
data
The data payload this object carries. |
(package private) static byte[] |
magic
This static field represents the magic sequence that distinguishes serialized ZObject instances. |
protected long |
seqnum
The sequence number that distinguishes that object. |
protected byte |
type
This field can be one of the following type: ACK_TYPE for ack object, COMPR_TYPE for compressed object, UNCOMPR_TYPE for uncompressed object (actually nonsense). |
static byte |
UNCOMPR_TYPE
|
| Constructor Summary | |
ZObject(byte[] _data)
Constructor used to build a compressed object with a specific data payload. |
|
ZObject(byte[] _data,
byte type)
Constructor used to build a generic ZObject instance. |
|
ZObject(DatagramPacket packet)
Constructor used to build an object by deserializing data coming from the buffer contained in the passed datagram. |
|
ZObject(java.io.InputStream in)
Constructor used to build an object by deserializing data coming from an input stream, tipically a socket input stream. |
|
ZObject(long seqnum)
Constructor used to build an ack object with a well-defined sequence number. |
|
| Method Summary | |
protected void |
create(byte[] _data,
byte type)
This method is responsible for generic object creation and it's an utility method used by constructors. |
protected static long |
deserialize(byte[] buf)
This method decodes an array of four bytes into a long value. |
boolean |
dump(byte[] buf,
int len)
|
byte[] |
getData()
This method returns the carried data payload. |
long |
getSeqNum()
This method returns the carried sequence number. |
protected static long |
positivize(long x)
This method positivize the passed long using steps of value 256. |
byte[] |
prepareData()
This method actually performs encoding on the internal object using a ByteArrayOutputStream as a container where internal fields get written into. |
protected static byte[] |
serialize(long num)
This method converts a passed long into a sequence of four bytes that can be written to an output stream. |
void |
setData(byte[] dat)
This method decodes the passed byte array trying to deserialize a ZObject instance. |
void |
setData(java.io.InputStream in)
This method decodes data from the input stream trying to deserialize a ZObject instance. |
java.lang.String |
toString()
Convert this Object to a human-readable String. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
magic
static byte[] magic
- This static field represents the magic sequence that distinguishes serialized
ZObject instances.
data
protected byte[] data
- The data payload this object carries. If it isn't an ack object, that buffer contains compressed
data.
type
protected byte type
- This field can be one of the following type:
- ACK_TYPE for ack object,
- COMPR_TYPE for compressed object,
- UNCOMPR_TYPE for uncompressed object (actually nonsense).
seqnum
protected long seqnum
- The sequence number that distinguishes that object.
If it's an ack object, the sequence number is the same as the compressed object
that generated it, otherwise is automagically generated (using the method
hashCode 55 applied to the data payload.
ACK_TYPE
public static byte ACK_TYPE
COMPR_TYPE
public static byte COMPR_TYPE
UNCOMPR_TYPE
public static byte UNCOMPR_TYPE
| Constructor Detail |
ZObject
public ZObject(long seqnum)
- Constructor used to build an ack object with a well-defined sequence number.
ZObject
public ZObject(java.io.InputStream in) throws java.io.IOException, AckException
- Constructor used to build an object by deserializing data coming from an input stream,
tipically a socket input stream.
ZObject
public ZObject(DatagramPacket packet) throws AckException, NoMagicException, java.io.IOException
- Constructor used to build an object by deserializing data coming from the buffer contained in
the passed datagram.
ZObject
public ZObject(byte[] _data,
byte type)
throws java.io.IOException
- Constructor used to build a generic ZObject instance.
ZObject
public ZObject(byte[] _data)
throws java.io.IOException
- Constructor used to build a compressed object with a specific data payload.
| Method Detail |
create
protected void create(byte[] _data,
byte type)
- This method is responsible for generic object creation and it's an utility method used by
constructors.
prepareData
public byte[] prepareData()
throws java.io.IOException
- This method actually performs encoding on the internal object using a ByteArrayOutputStream
as a container where internal fields get written into.
getSeqNum
public long getSeqNum()
- This method returns the carried sequence number.
getData
public byte[] getData()
- This method returns the carried data payload.
serialize
protected static byte[] serialize(long num)
- This method converts a passed long into a sequence of four bytes that can be written
to an output stream.
positivize
protected static long positivize(long x)
- This method positivize the passed long using steps of value 256. This ensure the following relation
always true:
<result> mod 256==x mod 256
deserialize
protected static long deserialize(byte[] buf)
- This method decodes an array of four bytes into a long value.
setData
public void setData(byte[] dat)
throws java.io.IOException,
AckException
- This method decodes the passed byte array trying to deserialize a ZObject instance.
dump
public boolean dump(byte[] buf,
int len)
setData
public void setData(java.io.InputStream in) throws java.io.IOException, AckException
- This method decodes data from the input stream trying to deserialize a ZObject instance.
toString
public java.lang.String toString()
- Description copied from class:
java.lang.Object - Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string concatenation with this object. If the result is
null, string concatenation will instead use"null".The default implementation returns
getClass().getName() + "@" + Integer.toHexString(hashCode()).
|
|||||||||
| Home >> All >> java >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
java.net.ZObject