1. /*
  2. * @(#)Externalizable.java 1.13 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.io;
  8. import java.io.ObjectOutput;
  9. import java.io.ObjectInput;
  10. /**
  11. * Only the identity of the class of an Externalizable instance is
  12. * written in the serialization stream and it is the responsibility
  13. * of the class to save and restore the contents of its instances.
  14. *
  15. * The writeExternal and readExternal methods of the Externalizable
  16. * interface are implemented by a class to give the class complete
  17. * control over the format and contents of the stream for an object
  18. * and its supertypes. These methods must explicitly
  19. * coordinate with the supertype to save its state. These methods supercede
  20. * customized implementations of writeObject and readObject methods.<br>
  21. *
  22. * Object Serialization uses the Serializable and Externalizable
  23. * interfaces. Object persistence mechanisms can use them as well. Each
  24. * object to be stored is tested for the Externalizable interface. If
  25. * the object supports Externalizable, the writeExternal method is called. If the
  26. * object does not support Externalizable and does implement
  27. * Serializable, the object is saved using
  28. * ObjectOutputStream. <br> When an Externalizable object is
  29. * reconstructed, an instance is created using the public no-arg
  30. * constructor, then the readExternal method called. Serializable
  31. * objects are restored by reading them from an ObjectInputStream.<br>
  32. *
  33. * An Externalizable instance can designate a substitution object via
  34. * the writeReplace and readResolve methods documented in the Serializable
  35. * interface.<br>
  36. *
  37. * @author unascribed
  38. * @version 1.13, 11/29/01
  39. * @see java.io.ObjectOutputStream
  40. * @see java.io.ObjectInputStream
  41. * @see java.io.ObjectOutput
  42. * @see java.io.ObjectInput
  43. * @see java.io.Serializable
  44. * @since JDK1.1
  45. */
  46. public interface Externalizable extends java.io.Serializable {
  47. /**
  48. * The object implements the writeExternal method to save its contents
  49. * by calling the methods of DataOutput for its primitive values or
  50. * calling the writeObject method of ObjectOutput for objects, strings,
  51. * and arrays.
  52. *
  53. * @serialData Overriding methods should use this tag to describe
  54. * the data layout of this Externalizable object.
  55. * List the sequence of element types and, if possible,
  56. * relate the element to a public/protected field and/or
  57. * method of this Externalizable class.
  58. *
  59. * @exception IOException Includes any I/O exceptions that may occur
  60. */
  61. void writeExternal(ObjectOutput out) throws IOException;
  62. /**
  63. * The object implements the readExternal method to restore its
  64. * contents by calling the methods of DataInput for primitive
  65. * types and readObject for objects, strings and arrays. The
  66. * readExternal method must read the values in the same sequence
  67. * and with the same types as were written by writeExternal.
  68. * @exception ClassNotFoundException If the class for an object being
  69. * restored cannot be found.
  70. */
  71. void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
  72. }