rt/emul/compact/src/main/java/java/io/Externalizable.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 601 emul/compact/src/main/java/java/io/Externalizable.java@5198affdb915
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
jaroslav@601
     1
/*
jaroslav@601
     2
 * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
jaroslav@601
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@601
     4
 *
jaroslav@601
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@601
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@601
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@601
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@601
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@601
    10
 *
jaroslav@601
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@601
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@601
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@601
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@601
    15
 * accompanied this code).
jaroslav@601
    16
 *
jaroslav@601
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@601
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@601
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@601
    20
 *
jaroslav@601
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@601
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@601
    23
 * questions.
jaroslav@601
    24
 */
jaroslav@601
    25
jaroslav@601
    26
package java.io;
jaroslav@601
    27
jaroslav@601
    28
import java.io.ObjectOutput;
jaroslav@601
    29
import java.io.ObjectInput;
jaroslav@601
    30
jaroslav@601
    31
/**
jaroslav@601
    32
 * Only the identity of the class of an Externalizable instance is
jaroslav@601
    33
 * written in the serialization stream and it is the responsibility
jaroslav@601
    34
 * of the class to save and restore the contents of its instances.
jaroslav@601
    35
 *
jaroslav@601
    36
 * The writeExternal and readExternal methods of the Externalizable
jaroslav@601
    37
 * interface are implemented by a class to give the class complete
jaroslav@601
    38
 * control over the format and contents of the stream for an object
jaroslav@601
    39
 * and its supertypes. These methods must explicitly
jaroslav@601
    40
 * coordinate with the supertype to save its state. These methods supersede
jaroslav@601
    41
 * customized implementations of writeObject and readObject methods.<br>
jaroslav@601
    42
 *
jaroslav@601
    43
 * Object Serialization uses the Serializable and Externalizable
jaroslav@601
    44
 * interfaces.  Object persistence mechanisms can use them as well.  Each
jaroslav@601
    45
 * object to be stored is tested for the Externalizable interface. If
jaroslav@601
    46
 * the object supports Externalizable, the writeExternal method is called. If the
jaroslav@601
    47
 * object does not support Externalizable and does implement
jaroslav@601
    48
 * Serializable, the object is saved using
jaroslav@601
    49
 * ObjectOutputStream. <br> When an Externalizable object is
jaroslav@601
    50
 * reconstructed, an instance is created using the public no-arg
jaroslav@601
    51
 * constructor, then the readExternal method called.  Serializable
jaroslav@601
    52
 * objects are restored by reading them from an ObjectInputStream.<br>
jaroslav@601
    53
 *
jaroslav@601
    54
 * An Externalizable instance can designate a substitution object via
jaroslav@601
    55
 * the writeReplace and readResolve methods documented in the Serializable
jaroslav@601
    56
 * interface.<br>
jaroslav@601
    57
 *
jaroslav@601
    58
 * @author  unascribed
jaroslav@601
    59
 * @see java.io.ObjectOutputStream
jaroslav@601
    60
 * @see java.io.ObjectInputStream
jaroslav@601
    61
 * @see java.io.ObjectOutput
jaroslav@601
    62
 * @see java.io.ObjectInput
jaroslav@601
    63
 * @see java.io.Serializable
jaroslav@601
    64
 * @since   JDK1.1
jaroslav@601
    65
 */
jaroslav@601
    66
public interface Externalizable extends java.io.Serializable {
jaroslav@601
    67
    /**
jaroslav@601
    68
     * The object implements the writeExternal method to save its contents
jaroslav@601
    69
     * by calling the methods of DataOutput for its primitive values or
jaroslav@601
    70
     * calling the writeObject method of ObjectOutput for objects, strings,
jaroslav@601
    71
     * and arrays.
jaroslav@601
    72
     *
jaroslav@601
    73
     * @serialData Overriding methods should use this tag to describe
jaroslav@601
    74
     *             the data layout of this Externalizable object.
jaroslav@601
    75
     *             List the sequence of element types and, if possible,
jaroslav@601
    76
     *             relate the element to a public/protected field and/or
jaroslav@601
    77
     *             method of this Externalizable class.
jaroslav@601
    78
     *
jaroslav@601
    79
     * @param out the stream to write the object to
jaroslav@601
    80
     * @exception IOException Includes any I/O exceptions that may occur
jaroslav@601
    81
     */
jaroslav@601
    82
    void writeExternal(ObjectOutput out) throws IOException;
jaroslav@601
    83
jaroslav@601
    84
    /**
jaroslav@601
    85
     * The object implements the readExternal method to restore its
jaroslav@601
    86
     * contents by calling the methods of DataInput for primitive
jaroslav@601
    87
     * types and readObject for objects, strings and arrays.  The
jaroslav@601
    88
     * readExternal method must read the values in the same sequence
jaroslav@601
    89
     * and with the same types as were written by writeExternal.
jaroslav@601
    90
     *
jaroslav@601
    91
     * @param in the stream to read data from in order to restore the object
jaroslav@601
    92
     * @exception IOException if I/O errors occur
jaroslav@601
    93
     * @exception ClassNotFoundException If the class for an object being
jaroslav@601
    94
     *              restored cannot be found.
jaroslav@601
    95
     */
jaroslav@601
    96
    void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
jaroslav@601
    97
}