0N/A/*
2362N/A * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.io;
0N/A
0N/A/**
0N/A * Serializability of a class is enabled by the class implementing the
0N/A * java.io.Serializable interface. Classes that do not implement this
0N/A * interface will not have any of their state serialized or
0N/A * deserialized. All subtypes of a serializable class are themselves
0N/A * serializable. The serialization interface has no methods or fields
0N/A * and serves only to identify the semantics of being serializable. <p>
0N/A *
0N/A * To allow subtypes of non-serializable classes to be serialized, the
0N/A * subtype may assume responsibility for saving and restoring the
0N/A * state of the supertype's public, protected, and (if accessible)
0N/A * package fields. The subtype may assume this responsibility only if
0N/A * the class it extends has an accessible no-arg constructor to
0N/A * initialize the class's state. It is an error to declare a class
0N/A * Serializable if this is not the case. The error will be detected at
0N/A * runtime. <p>
0N/A *
0N/A * During deserialization, the fields of non-serializable classes will
0N/A * be initialized using the public or protected no-arg constructor of
0N/A * the class. A no-arg constructor must be accessible to the subclass
0N/A * that is serializable. The fields of serializable subclasses will
0N/A * be restored from the stream. <p>
0N/A *
0N/A * When traversing a graph, an object may be encountered that does not
0N/A * support the Serializable interface. In this case the
0N/A * NotSerializableException will be thrown and will identify the class
0N/A * of the non-serializable object. <p>
0N/A *
0N/A * Classes that require special handling during the serialization and
0N/A * deserialization process must implement special methods with these exact
0N/A * signatures: <p>
0N/A *
0N/A * <PRE>
0N/A * private void writeObject(java.io.ObjectOutputStream out)
0N/A * throws IOException
0N/A * private void readObject(java.io.ObjectInputStream in)
0N/A * throws IOException, ClassNotFoundException;
0N/A * private void readObjectNoData()
0N/A * throws ObjectStreamException;
0N/A * </PRE>
0N/A *
0N/A * <p>The writeObject method is responsible for writing the state of the
0N/A * object for its particular class so that the corresponding
0N/A * readObject method can restore it. The default mechanism for saving
0N/A * the Object's fields can be invoked by calling
0N/A * out.defaultWriteObject. The method does not need to concern
0N/A * itself with the state belonging to its superclasses or subclasses.
0N/A * State is saved by writing the individual fields to the
0N/A * ObjectOutputStream using the writeObject method or by using the
0N/A * methods for primitive data types supported by DataOutput.
0N/A *
0N/A * <p>The readObject method is responsible for reading from the stream and
0N/A * restoring the classes fields. It may call in.defaultReadObject to invoke
0N/A * the default mechanism for restoring the object's non-static and
0N/A * non-transient fields. The defaultReadObject method uses information in
0N/A * the stream to assign the fields of the object saved in the stream with the
0N/A * correspondingly named fields in the current object. This handles the case
0N/A * when the class has evolved to add new fields. The method does not need to
0N/A * concern itself with the state belonging to its superclasses or subclasses.
0N/A * State is saved by writing the individual fields to the
0N/A * ObjectOutputStream using the writeObject method or by using the
0N/A * methods for primitive data types supported by DataOutput.
0N/A *
0N/A * <p>The readObjectNoData method is responsible for initializing the state of
0N/A * the object for its particular class in the event that the serialization
0N/A * stream does not list the given class as a superclass of the object being
0N/A * deserialized. This may occur in cases where the receiving party uses a
0N/A * different version of the deserialized instance's class than the sending
0N/A * party, and the receiver's version extends classes that are not extended by
0N/A * the sender's version. This may also occur if the serialization stream has
0N/A * been tampered; hence, readObjectNoData is useful for initializing
0N/A * deserialized objects properly despite a "hostile" or incomplete source
0N/A * stream.
0N/A *
0N/A * <p>Serializable classes that need to designate an alternative object to be
0N/A * used when writing an object to the stream should implement this
0N/A * special method with the exact signature: <p>
0N/A *
0N/A * <PRE>
0N/A * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
0N/A * </PRE><p>
0N/A *
0N/A * This writeReplace method is invoked by serialization if the method
0N/A * exists and it would be accessible from a method defined within the
0N/A * class of the object being serialized. Thus, the method can have private,
0N/A * protected and package-private access. Subclass access to this method
0N/A * follows java accessibility rules. <p>
0N/A *
0N/A * Classes that need to designate a replacement when an instance of it
0N/A * is read from the stream should implement this special method with the
0N/A * exact signature.<p>
0N/A *
0N/A * <PRE>
0N/A * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
0N/A * </PRE><p>
0N/A *
0N/A * This readResolve method follows the same invocation rules and
0N/A * accessibility rules as writeReplace.<p>
0N/A *
0N/A * The serialization runtime associates with each serializable class a version
0N/A * number, called a serialVersionUID, which is used during deserialization to
0N/A * verify that the sender and receiver of a serialized object have loaded
0N/A * classes for that object that are compatible with respect to serialization.
0N/A * If the receiver has loaded a class for the object that has a different
0N/A * serialVersionUID than that of the corresponding sender's class, then
0N/A * deserialization will result in an {@link InvalidClassException}. A
0N/A * serializable class can declare its own serialVersionUID explicitly by
0N/A * declaring a field named <code>"serialVersionUID"</code> that must be static,
0N/A * final, and of type <code>long</code>:<p>
0N/A *
0N/A * <PRE>
0N/A * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
0N/A * </PRE>
0N/A *
0N/A * If a serializable class does not explicitly declare a serialVersionUID, then
0N/A * the serialization runtime will calculate a default serialVersionUID value
0N/A * for that class based on various aspects of the class, as described in the
0N/A * Java(TM) Object Serialization Specification. However, it is <em>strongly
0N/A * recommended</em> that all serializable classes explicitly declare
0N/A * serialVersionUID values, since the default serialVersionUID computation is
0N/A * highly sensitive to class details that may vary depending on compiler
0N/A * implementations, and can thus result in unexpected
0N/A * <code>InvalidClassException</code>s during deserialization. Therefore, to
0N/A * guarantee a consistent serialVersionUID value across different java compiler
0N/A * implementations, a serializable class must declare an explicit
0N/A * serialVersionUID value. It is also strongly advised that explicit
0N/A * serialVersionUID declarations use the <code>private</code> modifier where
0N/A * possible, since such declarations apply only to the immediately declaring
0N/A * class--serialVersionUID fields are not useful as inherited members. Array
0N/A * classes cannot declare an explicit serialVersionUID, so they always have
0N/A * the default computed value, but the requirement for matching
0N/A * serialVersionUID values is waived for array classes.
0N/A *
0N/A * @author unascribed
0N/A * @see java.io.ObjectOutputStream
0N/A * @see java.io.ObjectInputStream
0N/A * @see java.io.ObjectOutput
0N/A * @see java.io.ObjectInput
0N/A * @see java.io.Externalizable
0N/A * @since JDK1.1
0N/A */
0N/Apublic interface Serializable {
0N/A}