PATH  Documentation > Mac OS X > Foundation Reference: Java



Table of Contents

NSUnarchiver


Inherits from:
NSCoder : NSObject
Package:
com.apple.yellow.foundation


Class Description


NSUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of objects from an archive. Such archives are produced by objects of the NSArchiver class. See the NSCoder and NSArchiver specifications for an introduction to archiving.


General Exception Conditions


While unarchiving, NSUnarchiver performs a variety of consistency checks on the incoming data stream. NSUnarchiver throws an InconsistentArchiveException when:

For a description of type codes, see the discussion of the @encode() compiler directive in Object-Oriented Programming and the Objective-C Language.

Invoking inappropriate methods can also lead to errors. NSUnarchiver's superclass, NSCoder, provides methods for both encoding and decoding. However, only the decoding methods are applicable to NSUnarchiver; don't send an NSUnarchiver any encode... messages.




Method Types


Constructors
NSUnarchiver
Decoding objects
decodeByte
decodeChar
decodeDataObject
decodeDouble
decodeFloat
decodeInt
decodeLong
decodeObject
decodeShort
unarchiveObjectWithData
unarchiveObjectWithFile
Encoding objects
encodeByte
encodeChar
encodeDataObject
encodeDouble
encodeFloat
encodeInt
encodeLong
encodeObject
encodeShort
Managing an NSUnarchiver
isAtEnd
versionForClassName
Substituting classes or objects
classNameDecodedForArchiveClassName
decodeClassNameAsClassName
classNameDecodedForArchiveClassName
decodeClassNameAsClassName
replaceObject


Constructors



NSUnarchiver

public NSUnarchiver()

Description forthcoming.

public NSUnarchiver(NSData aData)

Description forthcoming.


Static Methods



classNameGloballyDecodedForArchiveClassName

public static String classNameGloballyDecodedForArchiveClassName(String nameInArchive)

Returns the name of the class used when instantiating objects whose ostensible class, according to the archived data, is nameInArchive. This method returns nameInArchive if no substitute name has been specified using the static method (not the instance method) globallyDecodeClassNameAsClassName.

Note that individual instances of NSUnarchiver can each be given their own class name mappings by invoking the instance method decodeClassNameAsClassName. The NSUnarchiver class has no information about these instance-specific mappings, however, so they don't affect the return value of classNameGloballyDecodedForArchiveClassName.

See Also: classNameDecodedForArchiveClassName



globallyDecodeClassNameAsClassName

public static void globallyDecodeClassNameAsClassName( String nameInArchive, String trueName)

Instructs instances of NSUnarchiver to use the class named trueName when instantiating objects whose ostensible class, according to the archived data, is nameInArchive. This method enables easy conversion of unarchived data when the name of a class has changed since the archive was created.

See Also: classNameGloballyDecodedForArchiveClassName, decodeClassNameAsClassName



unarchiveObjectWithData

public static Object unarchiveObjectWithData(NSData data)

Decodes and returns the object archived in data. This method invokes initForReadingWithData:: and decodeObject to create a temporary NSUnarchiver that decodes the object. If the archived object is the root of a graph of objects, the entire graph is unarchived.

See Also: encodeRootObject (NSArchiver)



unarchiveObjectWithFile

public static Object unarchiveObjectWithFile(String path)

Decodes and returns the object archived in the file path. This convenience method reads the file by invoking NSData's dataWithContentsOfFile: method, and then invokes unarchiveObjectWithData.


Instance Methods



classNameDecodedForArchiveClassName

public String classNameDecodedForArchiveClassName(String nameInArchive)

Returns the name of the class that will be used when instantiating objects whose ostensible class, according to the archived data, is nameInArchive. This method returns nameInArchive unless a substitute name has been specified using the instance method (not the static method) decodeClassNameAsClassName.

See Also: classNameGloballyDecodedForArchiveClassName



data

public NSData data()

Description forthcoming.

decodeByte

public byte decodeByte()

Description forthcoming.

decodeChar

public char decodeChar()

Description forthcoming.

decodeClassNameAsClassName

public void decodeClassNameAsClassName( String nameInArchive, String trueName)

Instructs the receiver to use the class named trueName when instantiating objects whose ostensible class, according to the archived data, is nameInArchive. This method enables easy conversion of unarchived data when the name of a class has changed since the archive was created.

See Also: classNameDecodedForArchiveClassName, globallyDecodeClassNameAsClassName



decodeDataObject

public NSData decodeDataObject()

Description forthcoming.

decodeDouble

public double decodeDouble()

Description forthcoming.

decodeFloat

public float decodeFloat()

Description forthcoming.

decodeInt

public int decodeInt()

Description forthcoming.

decodeLong

public long decodeLong()

Description forthcoming.

decodeObject

public Object decodeObject()

Description forthcoming.

decodeShort

public short decodeShort()

Description forthcoming.

encodeByte

public void encodeByte(byte aByte)

Description forthcoming.

encodeChar

public void encodeChar(char aChar)

Description forthcoming.

encodeDataObject

public void encodeDataObject(NSData aData)

Description forthcoming.

encodeDouble

public void encodeDouble(double aDouble)

Description forthcoming.

encodeFloat

public void encodeFloat(float aFloat)

Description forthcoming.

encodeInt

public void encodeInt(int anInt)

Description forthcoming.

encodeLong

public void encodeLong(long aLong)

Description forthcoming.

encodeObject

public void encodeObject(Object anObject)

Description forthcoming.

encodeShort

public void encodeShort(short aShort)

Description forthcoming.

isAtEnd

public boolean isAtEnd()

Returns true if the NSUnarchiver has reached the end of the encoded data while decoding, false if more data follows. You can invoke this method after invoking decodeObject to discover whether the archive contains extra data following the encoded object graph. If it does, you can either ignore this anomaly or consider it an error.

replaceObject

public void replaceObject( Object object, Object newObject)

Causes the NSUnarchiver to substitute newObject for object whenever object is extracted from the archive. newObject can be of a different class from object, and the class mappings set by the two decodeClassName:asClassName: methods are ignored.

versionForClassName

public int versionForClassName(String aString)

Description forthcoming.


Table of Contents