PATH |
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()
Instance Methods
decodeBoolean
public abstract boolean decodeBoolean()
decodeByte
public abstract byte decodeByte()
decodeBytes
public abstract byte[] decodeBytes()
decodeChar
public abstract char decodeChar()
decodeClass
public abstract Class decodeClass()
decodeDouble
public abstract double decodeDouble()
decodeFloat
public abstract float decodeFloat()
decodeInt
public abstract int decodeInt()
decodeLong
public abstract long decodeLong()
decodeObject
public abstract Object decodeObject()
decodeObjects
public abstract Object[] decodeObjects()
decodeShort
public abstract short decodeShort()
encodeBoolean
public abstract void encodeBoolean(boolean aBoolean)
encodeByte
public abstract void encodeByte(byte aByte)
encodeBytes
public abstract void encodeBytes(byte[] bytes[])
encodeChar
public abstract void encodeChar(char aChar)
encodeClass
public abstract void encodeClass(Class aClass)
encodeDouble
public abstract void encodeDouble(double aDouble)
encodeFloat
public abstract void encodeFloat(float aFloat)
encodeInt
public abstract void encodeInt(int anInt)
encodeLong
public abstract void encodeLong(long aLong)
encodeObject
public abstract void encodeObject(Object anObject)
encodeObjects
public abstract void encodeObjects(Object[] anObject[])
encodeShort
public abstract void encodeShort(short aShort)
finishCoding
public void finishCoding()
prepareForReading
public void prepareForReading(java.io.InputStream inputStream)
prepareForWriting
public void prepareForWriting(java.io.OutputStream outputStream)
© 2001 Apple Computer, Inc. (Last Published April 17, 2001)