|CONTENTS | PREV | NEXT||Java Object Serialization Specification|
java.io.Externalizablemust implement the
readExternalmethod to restore the entire state of the object. It must coordinate with its superclasses to restore their state. All of the methods of
ObjectInputare available to restore the object's primitive typed fields and object fields.
public void readExternal(ObjectInput stream) throws IOException;
Note - The
readExternalmethod is public, and it raises the risk of a client being able to overwrite an existing object from a stream. The class may add its own checks to insure that this is only called when appropriate.
A new stream protocol version has been introduced in JDKTM 1.2 to correct a problem with
Externalizableobjects. The old definition of
Externalizableobjects required the local virtual machine to find a
readExternalmethod to be able to properly read an
Externalizableobject from the stream. The new format adds enough information to the stream protocol so serialization can skip an
Externalizableobject when the local
readExternalmethod is not available. Due to class evolution rules, serialization must be able to skip an
Externalizableobject in the input stream if there is not a mapping for the object using the local classes.
An additional benefit of the new
Externalizablestream format is the exception
EOFExceptionis thrown if a
readExternalmethod attempts to read beyond the end of an
Externalizableobject. Also, serialization is able to skip by any External data that is not read by a
Due to the format change, JDKTM 1.1.6 and earlier releases are not able to read the new format.
StreamCorruptedExceptionis thrown when JDKTM 1.1.6 or earlier attempts to read an
Externalizableobject from a stream written in
PROTOCOL_VERSION_2. Compatibility issues are discussed in more detail in Section 6.3, "Stream Protocol Versions."