src/java.base/share/classes/java/io/Externalizable.java
author bpb
Fri, 05 Jan 2018 12:45:52 -0800
changeset 48435 20fe8cd3179d
parent 47216 71c04702a3d5
child 58242 94bb65cb37d3
permissions -rw-r--r--
8193861: Typos in API documentation of File.toPath() and InetSocketAddress.getAddress() Reviewed-by: chegar, rriggs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ObjectOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ObjectInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Only the identity of the class of an Externalizable instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * written in the serialization stream and it is the responsibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * of the class to save and restore the contents of its instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The writeExternal and readExternal methods of the Externalizable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * interface are implemented by a class to give the class complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * control over the format and contents of the stream for an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * and its supertypes. These methods must explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * coordinate with the supertype to save its state. These methods supersede
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * customized implementations of writeObject and readObject methods.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Object Serialization uses the Serializable and Externalizable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * interfaces.  Object persistence mechanisms can use them as well.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * object to be stored is tested for the Externalizable interface. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * the object supports Externalizable, the writeExternal method is called. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * object does not support Externalizable and does implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Serializable, the object is saved using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * ObjectOutputStream. <br> When an Externalizable object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * reconstructed, an instance is created using the public no-arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * constructor, then the readExternal method called.  Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * objects are restored by reading them from an ObjectInputStream.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * An Externalizable instance can designate a substitution object via
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the writeReplace and readResolve methods documented in the Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * interface.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see java.io.ObjectOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see java.io.ObjectInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see java.io.ObjectOutput
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see java.io.ObjectInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see java.io.Serializable
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 5506
diff changeset
    64
 * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
public interface Externalizable extends java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * The object implements the writeExternal method to save its contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * by calling the methods of DataOutput for its primitive values or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * calling the writeObject method of ObjectOutput for objects, strings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * and arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @serialData Overriding methods should use this tag to describe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *             the data layout of this Externalizable object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *             List the sequence of element types and, if possible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *             relate the element to a public/protected field and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *             method of this Externalizable class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param out the stream to write the object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @exception IOException Includes any I/O exceptions that may occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    void writeExternal(ObjectOutput out) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * The object implements the readExternal method to restore its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * contents by calling the methods of DataInput for primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * types and readObject for objects, strings and arrays.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * readExternal method must read the values in the same sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * and with the same types as were written by writeExternal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param in the stream to read data from in order to restore the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @exception IOException if I/O errors occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @exception ClassNotFoundException If the class for an object being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *              restored cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}