org.instantreality.InstantIO
Class Decoder

java.lang.Object
  extended by org.instantreality.InstantIO.Decoder

public abstract class Decoder
extends java.lang.Object

Abstract superclass of all classes that decode data values.

The NetworkNode class uses decoders to decode values received from other components on the network. Before any data type can be transferred via the network, a Decoder has to be written that transforms a system and hardware independent byte stream to data values. For some frequently used data types, decoders already exist in this package, but when you need to transfer your own data types, you have to implement a Decoder.

For example, let's say you want to transfer Integer values via the network (a Decoder 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 Decoder class and implements the abstract decode method:

 public class MyIntDecoder extends Decoder
 {
   public final Object decode(DataInputStream dis)
   throws IOException
   {
     return new Integer(dis.readInt());
   }
 }
 
Then, you have to create a corresponding Encoder 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 Decoder (see documentation of the Codec class).

Author:
Patrick Dähne
See Also:
NetworkNode, Encoder, Codec

Constructor Summary
protected Decoder()
          Creates a new Decoder object.
 
Method Summary
abstract  java.lang.Object decode(java.io.DataInputStream dis)
          Decodes objects.
 void initialize(java.lang.String label, java.lang.Class type, java.lang.String description)
          Initializes the Decoder object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Decoder

protected Decoder()
Creates a new Decoder object.

Method Detail

initialize

public void initialize(java.lang.String label,
                       java.lang.Class type,
                       java.lang.String description)
Initializes the Decoder object.

Parameters:
label - The label of the OutSlot
type - The type of the OutSlot
description - The description of the OutSlot

decode

public abstract java.lang.Object decode(java.io.DataInputStream dis)
                                 throws java.io.IOException
Decodes objects. This method reads the binary representation of objects from an input stream and decodes objects from this binary representation. This method needs to be overwritten by your own implementations.

Parameters:
dis - The input stream you read the system and hardware independent byte stream from.
Returns:
The decoded object you create from the byte stream
Throws:
java.io.IOException - when the conversion fails (should never happen)