001 /* Externalizable.java -- Interface for saving and restoring object data 002 Copyright (C) 1998 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath 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 for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package java.io; 040 041 /** 042 * This interface provides a way that classes can completely control how 043 * the data of their object instances are written and read to and from 044 * streams. It has two methods which are used to write the data to a stream 045 * and to read the data from a stream. The read method must read the data 046 * in exactly the way it was written by the write method. 047 * <p> 048 * Note that classes which implement this interface must take into account 049 * that all superclass data must also be written to the stream as well. 050 * The class implementing this interface must figure out how to make that 051 * happen. 052 * <p> 053 * This interface can be used to provide object persistence. When an 054 * object is to be stored externally, the <code>writeExternal</code> method is 055 * called to save state. When the object is restored, an instance is 056 * created using the default no-argument constructor and the 057 * <code>readExternal</code> method is used to restore the state. 058 * 059 * @author Aaron M. Renn (arenn@urbanophile.com) 060 */ 061 public interface Externalizable extends Serializable 062 { 063 /** 064 * This method restores an object's state by reading in the instance data 065 * for the object from the passed in stream. Note that this stream is not 066 * a subclass of <code>InputStream</code>, but rather is a class that 067 * implements 068 * the <code>ObjectInput</code> interface. That interface provides a 069 * mechanism for 070 * reading in Java data types from a stream. 071 * <p> 072 * Note that this method must be compatible with <code>writeExternal</code>. 073 * It must read back the exact same types that were written by that 074 * method in the exact order they were written. 075 * <p> 076 * If this method needs to read back an object instance, then the class 077 * for that object must be found and loaded. If that operation fails, 078 * then this method throws a <code>ClassNotFoundException</code> 079 * 080 * @param in An <code>ObjectInput</code> instance for reading in the object 081 * state 082 * 083 * @exception ClassNotFoundException If the class of an object being 084 * restored cannot be found 085 * @exception IOException If any other error occurs 086 */ 087 void readExternal(ObjectInput in) 088 throws ClassNotFoundException, IOException; 089 090 /** 091 * This method is responsible for writing the instance data of an object 092 * to the passed in stream. Note that this stream is not a subclass of 093 * <code>OutputStream</code>, but rather is a class that implements the 094 * <code>ObjectOutput</code> interface. That interface provides a 095 * number of methods 096 * for writing Java data values to a stream. 097 * <p> 098 * Not that the implementation of this method must be coordinated with 099 * 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 }