Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

NSCoder


Inherits from:
Object
Package:
com.webobjects.foundation


Class Description


NSCoder is an abstract class that declares the API used by concrete subclasses to transfer objects and other data items between memory and 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).

You should never need to subclass NSCoder. Rather, WebObjects provides private concrete subclasses that it uses by default. However, you might interact with a coder object if you create a class that implements the NSCoding interface.

NSCoder operates on scalars (booleans, bytes, and integers, for example), and any other types of object. A coder object stores object type information along with an object's 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 NSCoder or by a concrete subclass to actually encode or decode the item. NSCoder itself defines no particular method for creating a coder; this typically varies with the subclass.

To encode an object or data item, use any of the encode... methods. To decode an object or data item, simply use the decode... method corresponding to the original encode... method. Matching these is important, as the method originally used determines the format of the encoded data.

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


Managing Object Graphs

Objects frequently contain references to other objects, which may in turn contain references to other objects. When analyzed, a group of objects may contain circular references or one object may be referred to by several other objects. In these cases, the objects form an object graph and require special handling to preserve the graph structure. NSCoder's encodeObject method preserves the graph structure.




Method Types


Encoding data
encodeBoolean
encodeByte
encodeBytes
encodeChar
encodeClass
encodeDouble
encodeFloat
encodeInt
encodeLong
encodeObject
encodeObjects
encodeShort
Decoding data
decodeBoolean
decodeByte
decodeBytes
decodeChar
decodeClass
decodeDouble
decodeFloat
decodeInt
decodeLong
decodeObject
decodeObjects
decodeShort
All methods
finishCoding
prepareForReading
prepareForWriting


Constructors



NSCoder

public NSCoder()

The no-arg constructor. Don't use this method; because NSCoder is an abstract class, you can never create an instance of it.


Instance Methods



decodeBoolean

public abstract boolean decodeBoolean()

Decodes and returns a boolean value that was previously encoded with encodeBoolean.

decodeByte

public abstract byte decodeByte()

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

decodeBytes

public abstract byte[] decodeBytes()

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

decodeChar

public abstract char decodeChar()

Decodes and returns a char value that was previously encoded with encodeChar.

decodeClass

public abstract Class decodeClass()

Decodes and returns a class that was previously encoded with encodeClass.

decodeDouble

public abstract double decodeDouble()

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

decodeFloat

public abstract float decodeFloat()

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

decodeInt

public abstract int decodeInt()

Decodes and returns an int value that was previously encoded with encodeInt.

decodeLong

public abstract long decodeLong()

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

decodeObject

public abstract Object decodeObject()

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

decodeObjects

public abstract Object[] decodeObjects()

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

decodeShort

public abstract short decodeShort()

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

encodeBoolean

public abstract void encodeBoolean(boolean aBoolean)

Encodes aBoolean. To decode a value encoded with this method, use decodeBoolean.

encodeByte

public abstract void encodeByte(byte aByte)

Encodes aByte. To decode a value encoded with this method, use decodeByte.

encodeBytes

public abstract void encodeBytes(byte[] bytes[])

Encodes the bytes array. To decode a value encoded with this method, use decodeBytes.

encodeChar

public abstract void encodeChar(char aChar)

Encodes aChar. To decode a value encoded with this method, use decodeChar.

encodeClass

public abstract void encodeClass(Class aClass)

Encodes aClass. To decode a value encoded with this method, use decodeClass.

encodeDouble

public abstract void encodeDouble(double aDouble)

Encodes aDouble. To decode a value encoded with this method, use decodeDouble.

encodeFloat

public abstract void encodeFloat(float aFloat)

Encodes aFloat. To decode a value encoded with this method, use decodeFloat.

encodeInt

public abstract void encodeInt(int anInt)

Encodes anInt. To decode a value encoded with this method, use decodeInt.

encodeLong

public abstract void encodeLong(long aLong)

Encodes aLong. To decode a value encoded with this method, use decodeLong.

encodeObject

public abstract void encodeObject(Object anObject)

Encodes anObject. To decode a value encoded with this method, use decodeObject.

encodeObjects

public abstract void encodeObjects(Object[] anObject[])

Encodes the objects array. To decode a value encoded with this method, use decodeObjects.

encodeShort

public abstract void encodeShort(short aShort)

Encodes aShort. To decode a value encoded with this method, use decodeShort.

finishCoding

public void finishCoding()

Cleans up the receiver's state after the receiver has finished encoding data. NSCoder's implementation does nothing.

prepareForReading

public void prepareForReading(java.io.InputStream inputStream)

Prepares the receiver for reading data from inputStream. NSCoder's implementation does nothing.

prepareForWriting

public void prepareForWriting(java.io.OutputStream outputStream)

Prepares the receiver for writing to outputStream. NSCoder's implementation does nothing.

© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents