001: /*
002: * @(#)Externalizable.java 1.22 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.io;
029:
030: import java.io.ObjectOutput;
031: import java.io.ObjectInput;
032:
033: /**
034: * Only the identity of the class of an Externalizable instance is
035: * written in the serialization stream and it is the responsibility
036: * of the class to save and restore the contents of its instances.
037: *
038: * The writeExternal and readExternal methods of the Externalizable
039: * interface are implemented by a class to give the class complete
040: * control over the format and contents of the stream for an object
041: * and its supertypes. These methods must explicitly
042: * coordinate with the supertype to save its state. These methods supercede
043: * customized implementations of writeObject and readObject methods.<br>
044: *
045: * Object Serialization uses the Serializable and Externalizable
046: * interfaces. Object persistence mechanisms can use them as well. Each
047: * object to be stored is tested for the Externalizable interface. If
048: * the object supports Externalizable, the writeExternal method is called. If the
049: * object does not support Externalizable and does implement
050: * Serializable, the object is saved using
051: * ObjectOutputStream. <br> When an Externalizable object is
052: * reconstructed, an instance is created using the public no-arg
053: * constructor, then the readExternal method called. Serializable
054: * objects are restored by reading them from an ObjectInputStream.<br>
055: *
056: * An Externalizable instance can designate a substitution object via
057: * the writeReplace and readResolve methods documented in the Serializable
058: * interface.<br>
059: *
060: * @author unascribed
061: * @version 1.15, 02/02/00
062: * @see java.io.ObjectOutputStream
063: * @see java.io.ObjectInputStream
064: * @see java.io.ObjectOutput
065: * @see java.io.ObjectInput
066: * @see java.io.Serializable
067: * @since JDK1.1
068: */
069: public interface Externalizable extends java.io.Serializable {
070: /**
071: * The object implements the writeExternal method to save its contents
072: * by calling the methods of DataOutput for its primitive values or
073: * calling the writeObject method of ObjectOutput for objects, strings,
074: * and arrays.
075: *
076: * @serialData Overriding methods should use this tag to describe
077: * the data layout of this Externalizable object.
078: * List the sequence of element types and, if possible,
079: * relate the element to a public/protected field and/or
080: * method of this Externalizable class.
081: *
082: * @param out the stream to write the object to
083: * @exception IOException Includes any I/O exceptions that may occur
084: */
085: void writeExternal(ObjectOutput out) throws IOException;
086:
087: /**
088: * The object implements the readExternal method to restore its
089: * contents by calling the methods of DataInput for primitive
090: * types and readObject for objects, strings and arrays. The
091: * readExternal method must read the values in the same sequence
092: * and with the same types as were written by writeExternal.
093: *
094: * @param in the stream to read data from in order to restore the object
095: * @exception IOException if I/O errors occur
096: * @exception ClassNotFoundException If the class for an object being
097: * restored cannot be found.
098: */
099: void readExternal(ObjectInput in) throws IOException,
100: ClassNotFoundException;
101: }
|