home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / io / Externalizable.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.5 KB  |  84 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Externalizable.java    1.12 98/06/29
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17. import java.io.ObjectOutput;
  18. import java.io.ObjectInput;
  19.  
  20. /**
  21.  * Only the identity of the class of an Externalizable instance is
  22.  * written in the serialization stream and it is the responsibility
  23.  * of the class to save and restore the contents of its instances.
  24.  *
  25.  * The writeExternal and readExternal methods of the Externalizable
  26.  * interface are implemented by a class to give the class complete
  27.  * control over the format and contents of the stream for an object
  28.  * and its supertypes. These methods must explicitly
  29.  * coordinate with the supertype to save its state. These methods supercede
  30.  * customized implementations of writeObject and readObject methods.<br>
  31.  *
  32.  * Object Serialization uses the Serializable and Externalizable
  33.  * interfaces.  Object persistence mechanisms can use them as well.  Each
  34.  * object to be stored is tested for the Externalizable interface. If
  35.  * the object supports Externalizable, the writeExternal method is called. If the
  36.  * object does not support Externalizable and does implement
  37.  * Serializable, the object is saved using
  38.  * ObjectOutputStream. <br> When an Externalizable object is
  39.  * reconstructed, an instance is created using the public no-arg
  40.  * constructor, then the readExternal method called.  Serializable
  41.  * objects are restored by reading them from an ObjectInputStream.<br>
  42.  *
  43.  * An Externalizable instance can designate a substitution object via
  44.  * the writeReplace and readResolve methods documented in the Serializable
  45.  * interface.<br>
  46.  *
  47.  * @author  unascribed
  48.  * @version 1.12, 06/29/98
  49.  * @see java.io.ObjectOutputStream
  50.  * @see java.io.ObjectInputStream
  51.  * @see java.io.ObjectOutput
  52.  * @see java.io.ObjectInput
  53.  * @see java.io.Serializable
  54.  * @since   JDK1.1
  55.  */
  56. public interface Externalizable extends java.io.Serializable {
  57.     /**
  58.      * The object implements the writeExternal method to save its contents
  59.      * by calling the methods of DataOutput for its primitive values or
  60.      * calling the writeObject method of ObjectOutput for objects, strings,
  61.      * and arrays.
  62.      *
  63.      * @serialData Overriding methods should use this tag to describe
  64.      *             the data layout of this Externalizable object.
  65.      *             List the sequence of element types and, if possible,
  66.      *             relate the element to a public/protected field and/or
  67.      *             method of this Externalizable class.
  68.      *
  69.      * @exception IOException Includes any I/O exceptions that may occur
  70.      */
  71.     void writeExternal(ObjectOutput out) throws IOException;
  72.  
  73.     /**
  74.      * The object implements the readExternal method to restore its
  75.      * contents by calling the methods of DataInput for primitive
  76.      * types and readObject for objects, strings and arrays.  The
  77.      * readExternal method must read the values in the same sequence
  78.      * and with the same types as were written by writeExternal.
  79.      * @exception ClassNotFoundException If the class for an object being
  80.      *              restored cannot be found.
  81.      */
  82.     void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
  83. }
  84.