2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / io / Externalizable.java
blob09080a0583178fd20e58290cfb0bda8724b89578
1 /* Externalizable.java -- Interface for saving and restoring object data
2 Copyright (C) 1998 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
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.
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. */
39 package java.io;
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.
59 * @author Aaron M. Renn (arenn@urbanophile.com)
61 public interface Externalizable extends Serializable
63 long serialVersionUID = -282491828744381764L;
65 /**
66 * This method restores an object's state by reading in the instance data
67 * for the object from the passed in stream. Note that this stream is not
68 * a subclass of <code>InputStream</code>, but rather is a class that
69 * implements
70 * the <code>ObjectInput</code> interface. That interface provides a
71 * mechanism for
72 * reading in Java data types from a stream.
73 * <p>
74 * Note that this method must be compatible with <code>writeExternal</code>.
75 * It must read back the exact same types that were written by that
76 * method in the exact order they were written.
77 * <p>
78 * If this method needs to read back an object instance, then the class
79 * for that object must be found and loaded. If that operation fails,
80 * then this method throws a <code>ClassNotFoundException</code>
82 * @param in An <code>ObjectInput</code> instance for reading in the object
83 * state
85 * @exception ClassNotFoundException If the class of an object being
86 * restored cannot be found
87 * @exception IOException If any other error occurs
89 void readExternal(ObjectInput in)
90 throws ClassNotFoundException, IOException;
92 /**
93 * This method is responsible for writing the instance data of an object
94 * to the passed in stream. Note that this stream is not a subclass of
95 * <code>OutputStream</code>, but rather is a class that implements the
96 * <code>ObjectOutput</code> interface. That interface provides a
97 * number of methods
98 * for writing Java data values to a stream.
99 * <p>
100 * Not that the implementation of this method must be coordinated with
101 * the implementation of <code>readExternal</code>.
103 * @param out An <code>ObjectOutput</code> instance for writing the
104 * object state
106 * @exception IOException If an error occurs
108 void writeExternal(ObjectOutput out) throws IOException;