Source for java.io.Externalizable

   1: /* Externalizable.java -- Interface for saving and restoring object data
   2:    Copyright (C) 1998 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.io;
  40: 
  41: /**
  42:  * This interface provides a way that classes can completely control how
  43:  * the data of their object instances  are written and read to and from
  44:  * streams.  It has two methods which are used to write the data to a stream
  45:  * and to read the data from a stream.  The read method must read the data
  46:  * in exactly the way it was written by the write method.
  47:  * <p>
  48:  * Note that classes which implement this interface must take into account
  49:  * that all superclass data must also be written to the stream as well.
  50:  * The class implementing this interface must figure out how to make that
  51:  * happen.
  52:  * <p>
  53:  * This interface can be used to provide object persistence.  When an
  54:  * object is to be stored externally, the <code>writeExternal</code> method is
  55:  * called to save state.  When the object is restored, an instance is
  56:  * created using the default no-argument constructor and the
  57:  * <code>readExternal</code> method is used to restore the state.
  58:  *
  59:  * @author Aaron M. Renn (arenn@urbanophile.com)
  60:  */
  61: public interface Externalizable extends Serializable
  62: {
  63:   /**
  64:    * This method restores an object's state by reading in the instance data
  65:    * for the object from the passed in stream.  Note that this stream is not
  66:    * a subclass of <code>InputStream</code>, but rather is a class that
  67:    * implements
  68:    * the <code>ObjectInput</code> interface.  That interface provides a
  69:    * mechanism for
  70:    * reading in Java data types from a stream.
  71:    * <p>
  72:    * Note that this method must be compatible with <code>writeExternal</code>.
  73:    * It must read back the exact same types that were written by that
  74:    * method in the exact order they were written.
  75:    * <p>
  76:    * If this method needs to read back an object instance, then the class
  77:    * for that object must be found and loaded.  If that operation fails,
  78:    * then this method throws a <code>ClassNotFoundException</code>
  79:    *
  80:    * @param in An <code>ObjectInput</code> instance for reading in the object
  81:    * state
  82:    *
  83:    * @exception ClassNotFoundException If the class of an object being
  84:    * restored cannot be found
  85:    * @exception IOException If any other error occurs
  86:    */
  87:   void readExternal(ObjectInput in)
  88:     throws ClassNotFoundException, IOException;
  89: 
  90:   /**
  91:    * This method is responsible for writing the instance data of an object
  92:    * to the passed in stream.  Note that this stream is not a subclass of
  93:    * <code>OutputStream</code>, but rather is a class that implements the
  94:    * <code>ObjectOutput</code> interface.  That interface provides a
  95:    * number of methods
  96:    * for writing Java data values to a stream.
  97:    * <p>
  98:    * Not that the implementation of this method must be coordinated with
  99:    * the implementation of <code>readExternal</code>.
 100:    *
 101:    * @param out An <code>ObjectOutput</code> instance for writing the
 102:    * object state
 103:    *
 104:    * @exception IOException If an error occurs
 105:    */
 106:   void writeExternal(ObjectOutput out) throws IOException;
 107: }