ObjectOutputStream.PutField


ObjectOutputStream.PutField java.io

Java 1.2

This class holds values of named fields and allows them to be written to an ObjectOutputStream during the process of object serialization. It gives the programmer precise control over the serialization process and is typically used when the set of fields defined by a class does not match the set of fields (and the serialization stream format) defined by the original implementation of the class. In other words, ObjectOutputStream.PutField allows the implementation of a class to change without breaking serialization compatibility.

In order to use the PutField class, you typically define a private static serialPersistentFields field that refers to an array of ObjectStreamField objects. This array defines the set of fields written to the ObjectOutputStream and therefore defines the serialization format. If you do not declare a serialPersistentFields field, the set of fields is all fields of the class, excluding static and TRansient fields.

In addition to the serialPersistentFields field, your class must also define a private writeObject( ) method that is responsible for the custom serialization of your class. In this method, call the putFields( ) method of ObjectOutputStream to obtain an ObjectOutputStream.PutField object. Once you have this object, use its various put( ) methods to specify the names and values of the field to be written out. The set of named fields should match those specified by serialPersistentFields . You may specify the fields in any order; the PutField class is responsible for writing them out in the correct order. Once you have specified the values of all fields, call the write( ) method of your PutField object in order to write the field values out to the serialization stream.

To reverse this custom serialization process, see ObjectInputStream.GetField .

 public abstract static class  ObjectOutputStream.PutField  {  // Public Constructors  public  PutField  ( );  // Public Instance Methods  public abstract void  put  (String  name  , long  val  );        public abstract void  put  (String  name  , int  val  );        public abstract void  put  (String  name  , float  val  );        public abstract void  put  (String  name  , Object  val  );        public abstract void  put  (String  name  , double  val  );        public abstract void  put  (String  name  , byte  val  );        public abstract void  put  (String  name  , boolean  val  );        public abstract void  put  (String  name  , short  val  );        public abstract void  put  (String  name  , char  val  );  // Deprecated Public Methods   #  public abstract void  write  (ObjectOutput  out  ) throws IOException;   } 

Returned By

ObjectOutputStream.putFields( )



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net