Class next.util.Coder

CLASS DESCRIPTION

Extends:
next.util.NextObject

Coder is a class that takes data from dynamic memory and codes them into and out of some other format. This capability provides the basis for archiving (where objects and data items are stored on disk) and distribution (where objects and data items are copied between different processes or threads).Instances of Coder are referred to as coder objects, or simply coders.

Coder operates on objects, scalars, and Java arrays. A coder object stores object type information along with the data, so an object decoded from a stream of bytes is normally of the same class as the object that was originally encoded into the stream.

Encoding and Decoding Objects and Data Items

To encode or decode an object or data item, you must first create a coder object, then send it a message defined by Coder or by a subclass to actually encode or decode the item.

To encode an object or data item, use any of the encode... methods.

In order for a coder to restore an object, the object must provide a constructor that takes a coder as its argument, as in the following:

public MyCodingClass(next.util.Coder coder)

This constructor would use the various decode... methods provided by this class to populate instance variables. These decode... methods must correspond to the original encode... methods (as given in the individual method descriptions). Matching these is important, as the method originally used determines the format of the encoded data. See the Coding interface specification for more information.

Coder's interface is quite general. Concrete subclasses aren't required to properly implement all of Coder's methods, and may explicitly restrict themselves to certain types of operations.

Managing Object Graphs

Objects frequently contain pointers to other objects, creating a graph of references that may contain cycles, objects that must be shared upon decoding, and inessential objects. Coder declares encodeObject; it allows a subclass to manage these cases.

CONSTRUCTORS

Coder

public Coder()

Returns a newly-allocated and initialized Coder object.


METHODS

decodeByte

public byte decodeByte()

Decodes and returns a single byte that was previously encoded with encodeByte.


decodeBytes

public byte[] decodeBytes()

Decodes and returns an array of bytes that were previously encoded with encodeBytes.


decodeChar

public char decodeChar()

Decodes and returns a single character that was previously encoded with encodeChar.


decodeChars

public char[] decodeChars()

Decodes and returns an array of characters that were previously encoded with encodeChars.


decodeDouble

public double decodeDouble()

Decodes and returns a double that was previously encoded with encodeDouble.


decodeDoubles

public double[] decodeDoubles()

Decodes and returns an array of doubles that were previously encoded with encodeDoubles.


decodeFloat

public float decodeFloat()

Decodes and returns a float that was previously encoded with encodeFloat.


decodeFloats

public float[] decodeFloats()

Decodes and returns an array of floats that were previously encoded with encodeFloats.


decodeInt

public int decodeInt()

Decodes and returns an integer that was previously encoded with encodeInt.


decodeInts

public int[] decodeInts()

Decodes and returns an array of integers that were previously encoded with encodeInts.


decodeLong

public long decodeLong()

Decodes and returns a long that was previously encoded with encodeLong.


decodeObject

public java.lang.Object decodeObject()

Decodes and returns an object that was previously encoded with encodeObject.


decodeObjects

public java.lang.Object[] decodeObjects()

Decodes and returns an array of objects that were previously encoded with encodeObjects.


decodeShort

public short decodeShort()

Decodes and returns a short integer that was previously encoded with encodeShort.


decodeShorts

public short[] decodeShorts()

Decodes and returns an array of short integers that were previously encoded with encodeShorts.


encodeByte

public void encodeByte(byte aByte)

Encodes aByte. This method must be matched by a subsequent decodeByte message.


encodeBytes

public void encodeBytes(byte[] bytes)

Encodes bytes. This method must be matched by a subsequent decodeBytes message.


encodeChar

public void encodeChar(char aChar)

Encodes aChar. This method must be matched by a subsequent decodeChar message.


encodeChars

public void encodeChars(char[] chars)

Encodes chars. This method must be matched by a subsequent decodeChars message.


encodeDouble

public void encodeDouble(double aDouble)

Encodes aDouble. This method must be matched by a subsequent decodeDouble message.


encodeDoubles

public void encodeDoubles(double[] doubles)

Encodes doubles. This method must be matched by a subsequent decodeDoubles message.


encodeFloat

public void encodeFloat(float aFloat)

Encodes aFloat. This method must be matched by a subsequent decodeFloat message.


encodeFloats

public void encodeFloats(float[] floats)

Encodes floats. This method must be matched by a subsequent decodeFloats message.


encodeInt

public void encodeInt(int anInt)

Encodes anInt. This method must be matched by a subsequent decodeInt message.


encodeInts

public void encodeInts(int[] ints)

Encodes ints. This method must be matched by a subsequent decodeInts message.


encodeLong

public void encodeLong(long aLong)

Encodes aLong. This method must be matched by a subsequent decodeLong message.


encodeObject

public void encodeObject(java.lang.Object anObject)

Encodes anObject. This method must be matched by a subsequent decodeObject message.


encodeObjects

public void encodeObjects(next.util.Coding[] objects)

Encodes objects. This method must be matched by a subsequent decodeObjects message.


encodeShort

public void encodeShort(short aShort)

Encodes aShort. This method must be matched by a subsequent decodeShort message.


encodeShorts

public void encodeShorts(short[] shorts)

Encodes shorts. This method must be matched by a subsequent decodeShorts message.