Code example for ObjectOutputStream

Methods: putFields, writeFields

0
    public ObjectInputStream.GetField getGetField() {
        return getField;
    } 
 
    private void writeObject(ObjectOutputStream o) throws IOException {
        ObjectOutputStream.PutField putField = o.putFields();
        putField.put("i", new Integer(1000));
        putField.put("d", today);
        putField.put("s", "Richard");
        o.writeFields();
    } 
 
    private void readObject(ObjectInputStream in) throws NotActiveException,
            IOException, ClassNotFoundException { 
        getField = in.readFields();
    } 
} 
 
 
// Primitive fields are necessary to cause the NullPointerException.  
class MockClass implements Serializable {