jaroslav@601: /*
jaroslav@601: * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
jaroslav@601: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@601: *
jaroslav@601: * This code is free software; you can redistribute it and/or modify it
jaroslav@601: * under the terms of the GNU General Public License version 2 only, as
jaroslav@601: * published by the Free Software Foundation. Oracle designates this
jaroslav@601: * particular file as subject to the "Classpath" exception as provided
jaroslav@601: * by Oracle in the LICENSE file that accompanied this code.
jaroslav@601: *
jaroslav@601: * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@601: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@601: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jaroslav@601: * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@601: * accompanied this code).
jaroslav@601: *
jaroslav@601: * You should have received a copy of the GNU General Public License version
jaroslav@601: * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@601: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@601: *
jaroslav@601: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@601: * or visit www.oracle.com if you need additional information or have any
jaroslav@601: * questions.
jaroslav@601: */
jaroslav@601:
jaroslav@601: package java.io;
jaroslav@601:
jaroslav@601: import java.io.ObjectOutput;
jaroslav@601: import java.io.ObjectInput;
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Only the identity of the class of an Externalizable instance is
jaroslav@601: * written in the serialization stream and it is the responsibility
jaroslav@601: * of the class to save and restore the contents of its instances.
jaroslav@601: *
jaroslav@601: * The writeExternal and readExternal methods of the Externalizable
jaroslav@601: * interface are implemented by a class to give the class complete
jaroslav@601: * control over the format and contents of the stream for an object
jaroslav@601: * and its supertypes. These methods must explicitly
jaroslav@601: * coordinate with the supertype to save its state. These methods supersede
jaroslav@601: * customized implementations of writeObject and readObject methods.
jaroslav@601: *
jaroslav@601: * Object Serialization uses the Serializable and Externalizable
jaroslav@601: * interfaces. Object persistence mechanisms can use them as well. Each
jaroslav@601: * object to be stored is tested for the Externalizable interface. If
jaroslav@601: * the object supports Externalizable, the writeExternal method is called. If the
jaroslav@601: * object does not support Externalizable and does implement
jaroslav@601: * Serializable, the object is saved using
jaroslav@601: * ObjectOutputStream.
When an Externalizable object is
jaroslav@601: * reconstructed, an instance is created using the public no-arg
jaroslav@601: * constructor, then the readExternal method called. Serializable
jaroslav@601: * objects are restored by reading them from an ObjectInputStream.
jaroslav@601: *
jaroslav@601: * An Externalizable instance can designate a substitution object via
jaroslav@601: * the writeReplace and readResolve methods documented in the Serializable
jaroslav@601: * interface.
jaroslav@601: *
jaroslav@601: * @author unascribed
jaroslav@601: * @see java.io.ObjectOutputStream
jaroslav@601: * @see java.io.ObjectInputStream
jaroslav@601: * @see java.io.ObjectOutput
jaroslav@601: * @see java.io.ObjectInput
jaroslav@601: * @see java.io.Serializable
jaroslav@601: * @since JDK1.1
jaroslav@601: */
jaroslav@601: public interface Externalizable extends java.io.Serializable {
jaroslav@601: /**
jaroslav@601: * The object implements the writeExternal method to save its contents
jaroslav@601: * by calling the methods of DataOutput for its primitive values or
jaroslav@601: * calling the writeObject method of ObjectOutput for objects, strings,
jaroslav@601: * and arrays.
jaroslav@601: *
jaroslav@601: * @serialData Overriding methods should use this tag to describe
jaroslav@601: * the data layout of this Externalizable object.
jaroslav@601: * List the sequence of element types and, if possible,
jaroslav@601: * relate the element to a public/protected field and/or
jaroslav@601: * method of this Externalizable class.
jaroslav@601: *
jaroslav@601: * @param out the stream to write the object to
jaroslav@601: * @exception IOException Includes any I/O exceptions that may occur
jaroslav@601: */
jaroslav@601: void writeExternal(ObjectOutput out) throws IOException;
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * The object implements the readExternal method to restore its
jaroslav@601: * contents by calling the methods of DataInput for primitive
jaroslav@601: * types and readObject for objects, strings and arrays. The
jaroslav@601: * readExternal method must read the values in the same sequence
jaroslav@601: * and with the same types as were written by writeExternal.
jaroslav@601: *
jaroslav@601: * @param in the stream to read data from in order to restore the object
jaroslav@601: * @exception IOException if I/O errors occur
jaroslav@601: * @exception ClassNotFoundException If the class for an object being
jaroslav@601: * restored cannot be found.
jaroslav@601: */
jaroslav@601: void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
jaroslav@601: }