|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.instantreality.InstantIO.Encoder
public abstract class Encoder
Abstract superclass of all classes that encode data values.
The NetworkNode
class uses
encoders to encode values before they are sent to other
components on the network. Before any data type can
be transferred via the network, an Encoder has to be written
that transforms the data values to a system and hardware
independent byte stream. For some frequently used data types,
encoders already exist in this package, but when you need
to transfer your own data types, you have to implement an
Encoder.
For example, let's say you want to transfer Integer
values via the network (an Encoder for
Integer
of course already exists in this package,
but for the sake of demonstrating the procedure whe
nevertheless demonstrate how to create your own). First, you
have to create a class that inherits from the Encoder class
and implements the abstract encode
method:
Then, you have to create a corresponding
public class MyIntEncoder extends Encoder
{
public final void encode(DataOutputStream dos, Object value)
throws IOException
{
Integer i = (Integer)value;
dos.writeInt(i.intValue());
}
}
Decoder
class (see the documentation of this class for
more information about how to do that). Finally, you have
to create an instance of the Codec
class so
that the NetworkNode can actually access your Encoder
(see documentation of the Codec class).
NetworkNode
,
Decoder
,
Codec
Constructor Summary | |
---|---|
protected |
Encoder()
Creates a new Encoder object. |
Method Summary | |
---|---|
abstract void |
encode(java.io.DataOutputStream dos,
java.lang.Object value)
Encodes objects. |
void |
initialize(java.lang.String label,
java.lang.Class type,
java.lang.String description)
Initializes the Encoder object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected Encoder()
Method Detail |
---|
public void initialize(java.lang.String label, java.lang.Class type, java.lang.String description)
label
- The label of the InSlottype
- The type of the InSlotdescription
- The description of the InSlotpublic abstract void encode(java.io.DataOutputStream dos, java.lang.Object value) throws java.io.IOException
dos
- The output stream you write the system and hardware
independent byte representation to.value
- The object you have to encode.
java.io.IOException
- when the conversion fails (should
never happen)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |