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., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 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 | * @version 0.0
|
---|
60 | *
|
---|
61 | * @author Aaron M. Renn (arenn@urbanophile.com)
|
---|
62 | */
|
---|
63 | public interface Externalizable extends Serializable
|
---|
64 | {
|
---|
65 | static final long serialVersionUID = -282491828744381764L;
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * This method restores an object's state by reading in the instance data
|
---|
69 | * for the object from the passed in stream. Note that this stream is not
|
---|
70 | * a subclass of <code>InputStream</code>, but rather is a class that implements
|
---|
71 | * the <code>ObjectInput</code> interface. That interface provides a 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>
|
---|
81 | *
|
---|
82 | * @param in An <code>ObjectInput</code> instance for reading in the object state
|
---|
83 | *
|
---|
84 | * @exception ClassNotFoundException If the class of an object being restored cannot be found
|
---|
85 | * @exception IOException If any other error occurs
|
---|
86 | */
|
---|
87 | public abstract void
|
---|
88 | readExternal(ObjectInput in) throws ClassNotFoundException, IOException;
|
---|
89 |
|
---|
90 | /*************************************************************************/
|
---|
91 |
|
---|
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 number of methods
|
---|
97 | * for writing Java data values to a stream.
|
---|
98 | * <p>
|
---|
99 | * Not that the implementation of this method must be coordinated with
|
---|
100 | * the implementation of <code>readExternal</code>.
|
---|
101 | *
|
---|
102 | * @param out An <code>ObjectOutput</code> instance for writing the object state
|
---|
103 | *
|
---|
104 | * @exception IOException If an error occurs
|
---|
105 | */
|
---|
106 | public abstract void
|
---|
107 | writeExternal(ObjectOutput out) throws IOException;
|
---|
108 |
|
---|
109 | } // interface Externalizable
|
---|
110 |
|
---|