Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/io/Externalizable.java
38829 views
/*1* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.io;2627import java.io.ObjectOutput;28import java.io.ObjectInput;2930/**31* Only the identity of the class of an Externalizable instance is32* written in the serialization stream and it is the responsibility33* of the class to save and restore the contents of its instances.34*35* The writeExternal and readExternal methods of the Externalizable36* interface are implemented by a class to give the class complete37* control over the format and contents of the stream for an object38* and its supertypes. These methods must explicitly39* coordinate with the supertype to save its state. These methods supersede40* customized implementations of writeObject and readObject methods.<br>41*42* Object Serialization uses the Serializable and Externalizable43* interfaces. Object persistence mechanisms can use them as well. Each44* object to be stored is tested for the Externalizable interface. If45* the object supports Externalizable, the writeExternal method is called. If the46* object does not support Externalizable and does implement47* Serializable, the object is saved using48* ObjectOutputStream. <br> When an Externalizable object is49* reconstructed, an instance is created using the public no-arg50* constructor, then the readExternal method called. Serializable51* objects are restored by reading them from an ObjectInputStream.<br>52*53* An Externalizable instance can designate a substitution object via54* the writeReplace and readResolve methods documented in the Serializable55* interface.<br>56*57* @author unascribed58* @see java.io.ObjectOutputStream59* @see java.io.ObjectInputStream60* @see java.io.ObjectOutput61* @see java.io.ObjectInput62* @see java.io.Serializable63* @since JDK1.164*/65public interface Externalizable extends java.io.Serializable {66/**67* The object implements the writeExternal method to save its contents68* by calling the methods of DataOutput for its primitive values or69* calling the writeObject method of ObjectOutput for objects, strings,70* and arrays.71*72* @serialData Overriding methods should use this tag to describe73* the data layout of this Externalizable object.74* List the sequence of element types and, if possible,75* relate the element to a public/protected field and/or76* method of this Externalizable class.77*78* @param out the stream to write the object to79* @exception IOException Includes any I/O exceptions that may occur80*/81void writeExternal(ObjectOutput out) throws IOException;8283/**84* The object implements the readExternal method to restore its85* contents by calling the methods of DataInput for primitive86* types and readObject for objects, strings and arrays. The87* readExternal method must read the values in the same sequence88* and with the same types as were written by writeExternal.89*90* @param in the stream to read data from in order to restore the object91* @exception IOException if I/O errors occur92* @exception ClassNotFoundException If the class for an object being93* restored cannot be found.94*/95void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;96}979899