Java Code Examples for java.io.ObjectOutputStream.PutField

The following are Jave code examples for showing how to use PutField of the java.io.ObjectOutputStream class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: MBeanServerNotificationFilter.java   View Source Code Vote up 6 votes
/**
 * Serializes an {@link MBeanServerNotificationFilter} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("mySelectObjNameList", selectedNames);
    fields.put("myDeselectObjNameList", deselectedNames);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 2
Project: OpenJSharp   File: InvalidTargetObjectTypeException.java   View Source Code Vote up 6 votes
/**
 * Serializes an {@link InvalidTargetObjectTypeException} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("relatedExcept", exception);
    fields.put("msgStr", ((exception != null)?exception.getMessage():""));
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 3
Project: jdk8u-jdk   File: ModelMBeanAttributeInfo.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link ModelMBeanAttributeInfo} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("attrDescriptor", attrDescriptor);
    fields.put("currClass", currClass);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 4
Project: gate-core   File: AnnotationSetImpl.java   View Source Code Vote up 6 votes
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
  ObjectOutputStream.PutField pf = out.putFields();
  pf.put("name", this.name);
  pf.put("doc", this.doc);
  //
  // out.writeObject(this.name);
  // out.writeObject(this.doc);
  // save only the annotations
  // in an array that will prevent the need for casting
  // when deserializing
  annotations = new Annotation[this.annotsById.size()];
  annotations = this.annotsById.values().toArray(annotations);
  // out.writeObject(annotations);
  pf.put("annotations", this.annotations);    
  pf.put("relations", this.relations);
  
  
  out.writeFields();
  annotations = null;
  boolean isIndexedByType = (this.annotsByType != null);
  boolean isIndexedByStartNode = (this.annotsByStartNode != null);
  out.writeBoolean(isIndexedByType);
  out.writeBoolean(isIndexedByStartNode);
}
 
Example 5
Project: jdk8u-jdk   File: Inet6Address.java   View Source Code Vote up 6 votes
/**
 * default behavior is overridden in order to write the
 * scope_ifname field as a String, rather than a NetworkInterface
 * which is not serializable
 */
private synchronized void writeObject(ObjectOutputStream s)
    throws IOException
{
        String ifname = null;

    if (holder6.scope_ifname != null) {
        ifname = holder6.scope_ifname.getName();
        holder6.scope_ifname_set = true;
    }
    ObjectOutputStream.PutField pfields = s.putFields();
    pfields.put("ipaddress", holder6.ipaddress);
    pfields.put("scope_id", holder6.scope_id);
    pfields.put("scope_id_set", holder6.scope_id_set);
    pfields.put("scope_ifname_set", holder6.scope_ifname_set);
    pfields.put("ifname", ifname);
    s.writeFields();
}
 
Example 6
Project: jdk8u-jdk   File: BigInteger.java   View Source Code Vote up 6 votes
/**
     * Save the {@code BigInteger} instance to a stream.
     * The magnitude of a BigInteger is serialized as a byte array for
     * historical reasons.
     *
     * @serialData two necessary fields are written as well as obsolete
     *             fields for compatibility with older versions.
     */
    private void writeObject(ObjectOutputStream s) throws IOException {
        // set the values of the Serializable fields
        ObjectOutputStream.PutField fields = s.putFields();
        fields.put("signum", signum);
        fields.put("magnitude", magSerializedForm());
        // The values written for cached fields are compatible with older
        // versions, but are ignored in readObject so don't otherwise matter.
        fields.put("bitCount", -1);
        fields.put("bitLength", -1);
        fields.put("lowestSetBit", -2);
        fields.put("firstNonzeroByteNum", -2);

        // save them
        s.writeFields();
}
 
Example 7
Project: OpenJSharp   File: RelationNotification.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link RelationNotification} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("myNewRoleValue", newRoleValue);
    fields.put("myOldRoleValue", oldRoleValue);
    fields.put("myRelId", relationId);
    fields.put("myRelObjName", relationObjName);
    fields.put("myRelTypeName", relationTypeName);
    fields.put("myRoleName",roleName);
    fields.put("myUnregMBeanList", unregisterMBeanList);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 8
Project: openjdk-jdk10   File: BigInteger.java   View Source Code Vote up 6 votes
/**
 * Save the {@code BigInteger} instance to a stream.  The magnitude of a
 * {@code BigInteger} is serialized as a byte array for historical reasons.
 * To maintain compatibility with older implementations, the integers
 * -1, -1, -2, and -2 are written as the values of the obsolete fields
 * {@code bitCount}, {@code bitLength}, {@code lowestSetBit}, and
 * {@code firstNonzeroByteNum}, respectively.  These values are compatible
 * with older implementations, but will be ignored by current
 * implementations.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    // set the values of the Serializable fields
    ObjectOutputStream.PutField fields = s.putFields();
    fields.put("signum", signum);
    fields.put("magnitude", magSerializedForm());
    // The values written for cached fields are compatible with older
    // versions, but are ignored in readObject so don't otherwise matter.
    fields.put("bitCount", -1);
    fields.put("bitLength", -1);
    fields.put("lowestSetBit", -2);
    fields.put("firstNonzeroByteNum", -2);

    // save them
    s.writeFields();
}
 
Example 9
Project: openjdk-jdk10   File: InvalidTargetObjectTypeException.java   View Source Code Vote up 6 votes
/**
 * Serializes an {@link InvalidTargetObjectTypeException} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("relatedExcept", exception);
    fields.put("msgStr", ((exception != null)?exception.getMessage():""));
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 10
Project: jdk8u-jdk   File: ModelMBeanNotificationInfo.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link ModelMBeanNotificationInfo} to an
 * {@link ObjectOutputStream}.
 **/
private void writeObject(ObjectOutputStream out)
    throws IOException {
    if (compat) {
        // Serializes this instance in the old serial form
        //
        ObjectOutputStream.PutField fields = out.putFields();
        fields.put("notificationDescriptor", notificationDescriptor);
        fields.put("currClass", currClass);
        out.writeFields();
    } else {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
    }
}
 
Example 11
Project: openjdk-jdk10   File: CardLayout.java   View Source Code Vote up 6 votes
/**
 * Writes serializable fields to stream.
 */
private void writeObject(ObjectOutputStream s)
    throws IOException
{
    Hashtable<String, Component> tab = new Hashtable<>();
    int ncomponents = vector.size();
    for (int i = 0; i < ncomponents; i++) {
        Card card = vector.get(i);
        tab.put(card.name, card.comp);
    }

    ObjectOutputStream.PutField f = s.putFields();
    f.put("hgap", hgap);
    f.put("vgap", vgap);
    f.put("vector", vector);
    f.put("currentCard", currentCard);
    f.put("tab", tab);
    s.writeFields();
}
 
Example 12
Project: jdk8u-jdk   File: NumericValueExp.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link NumericValueExp} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("doubleVal", doubleValue());
    fields.put("longVal", longValue());
    fields.put("valIsLong", isLong());
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 13
Project: jdk8u-jdk   File: RelationTypeSupport.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link RelationTypeSupport} to an {@link ObjectOutputStream}.
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {
  if (compat)
  {
    // Serializes this instance in the old serial form
    //
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("myTypeName", typeName);
    fields.put("myRoleName2InfoMap", roleName2InfoMap);
    fields.put("myIsInRelServFlg", isInRelationService);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 14
Project: OpenJSharp   File: VetoableChangeSupport.java   View Source Code Vote up 5 votes
/**
 * @serialData Null terminated list of <code>VetoableChangeListeners</code>.
 * <p>
 * At serialization time we skip non-serializable listeners and
 * only serialize the serializable listeners.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    Hashtable<String, VetoableChangeSupport> children = null;
    VetoableChangeListener[] listeners = null;
    synchronized (this.map) {
        for (Entry<String, VetoableChangeListener[]> entry : this.map.getEntries()) {
            String property = entry.getKey();
            if (property == null) {
                listeners = entry.getValue();
            } else {
                if (children == null) {
                    children = new Hashtable<>();
                }
                VetoableChangeSupport vcs = new VetoableChangeSupport(this.source);
                vcs.map.set(null, entry.getValue());
                children.put(property, vcs);
            }
        }
    }
    ObjectOutputStream.PutField fields = s.putFields();
    fields.put("children", children);
    fields.put("source", this.source);
    fields.put("vetoableChangeSupportSerializedDataVersion", 2);
    s.writeFields();

    if (listeners != null) {
        for (VetoableChangeListener l : listeners) {
            if (l instanceof Serializable) {
                s.writeObject(l);
            }
        }
    }
    s.writeObject(null);
}
 
Example 15
Project: OpenJSharp   File: BatchUpdateException.java   View Source Code Vote up 5 votes
/**
 * writeObject is called to save the state of the {@code BatchUpdateException}
 * to a stream.
 */
private void writeObject(ObjectOutputStream s)
        throws IOException, ClassNotFoundException {

    ObjectOutputStream.PutField fields = s.putFields();
    fields.put("updateCounts", updateCounts);
    fields.put("longUpdateCounts", longUpdateCounts);
    s.writeFields();
}
 
Example 16
Project: jdk8u-jdk   File: PropertyChangeSupport.java   View Source Code Vote up 5 votes
/**
 * @serialData Null terminated list of <code>PropertyChangeListeners</code>.
 * <p>
 * At serialization time we skip non-serializable listeners and
 * only serialize the serializable listeners.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    Hashtable<String, PropertyChangeSupport> children = null;
    PropertyChangeListener[] listeners = null;
    synchronized (this.map) {
        for (Entry<String, PropertyChangeListener[]> entry : this.map.getEntries()) {
            String property = entry.getKey();
            if (property == null) {
                listeners = entry.getValue();
            } else {
                if (children == null) {
                    children = new Hashtable<>();
                }
                PropertyChangeSupport pcs = new PropertyChangeSupport(this.source);
                pcs.map.set(null, entry.getValue());
                children.put(property, pcs);
            }
        }
    }
    ObjectOutputStream.PutField fields = s.putFields();
    fields.put("children", children);
    fields.put("source", this.source);
    fields.put("propertyChangeSupportSerializedDataVersion", 2);
    s.writeFields();

    if (listeners != null) {
        for (PropertyChangeListener l : listeners) {
            if (l instanceof Serializable) {
                s.writeObject(l);
            }
        }
    }
    s.writeObject(null);
}
 
Example 17
Project: openjdk-jdk10   File: DelegationPermission.java   View Source Code Vote up 5 votes
/**
 * @serialData "permissions" field (a Vector containing the DelegationPermissions).
 */
/*
 * Writes the contents of the perms field out as a Vector for
 * serialization compatibility with earlier releases.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Don't call out.defaultWriteObject()

    // Write out Vector
    Vector<Permission> permissions = new Vector<>(perms.keySet());

    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("permissions", permissions);
    out.writeFields();
}
 
Example 18
Project: openjdk-jdk10   File: Container.java   View Source Code Vote up 4 votes
/**
 * Serializes this {@code Container} to the specified
 * {@code ObjectOutputStream}.
 * <ul>
 *    <li>Writes default serializable fields to the stream.</li>
 *    <li>Writes a list of serializable ContainerListener(s) as optional
 *        data. The non-serializable ContainerListener(s) are detected and
 *        no attempt is made to serialize them.</li>
 *    <li>Write this Container's FocusTraversalPolicy if and only if it
 *        is Serializable; otherwise, {@code null} is written.</li>
 * </ul>
 *
 * @param s the {@code ObjectOutputStream} to write
 * @serialData {@code null} terminated sequence of 0 or more pairs;
 *   the pair consists of a {@code String} and {@code Object};
 *   the {@code String} indicates the type of object and
 *   is one of the following:
 *   {@code containerListenerK} indicating an
 *     {@code ContainerListener} object;
 *   the {@code Container}'s {@code FocusTraversalPolicy},
 *     or {@code null}
 *
 * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
 * @see Container#containerListenerK
 * @see #readObject(ObjectInputStream)
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    ObjectOutputStream.PutField f = s.putFields();
    f.put("ncomponents", component.size());
    f.put("component", component.toArray(EMPTY_ARRAY));
    f.put("layoutMgr", layoutMgr);
    f.put("dispatcher", dispatcher);
    f.put("maxSize", maxSize);
    f.put("focusCycleRoot", focusCycleRoot);
    f.put("containerSerializedDataVersion", containerSerializedDataVersion);
    f.put("focusTraversalPolicyProvider", focusTraversalPolicyProvider);
    s.writeFields();

    AWTEventMulticaster.save(s, containerListenerK, containerListener);
    s.writeObject(null);

    if (focusTraversalPolicy instanceof java.io.Serializable) {
        s.writeObject(focusTraversalPolicy);
    } else {
        s.writeObject(null);
    }
}
 
Example 19
Project: jdk8u-jdk   File: AbstractObjectOutputStream.java   View Source Code Vote up 4 votes
/*************************************************************/
/* Use the methods of PutField to map between Serializable fields
 * and actual fields of a Serializable class.
 */

abstract public ObjectOutputStream.PutField putFields() throws IOException;
 
Example 20
Project: openjdk-jdk10   File: AbstractObjectOutputStream.java   View Source Code Vote up 4 votes
/*************************************************************/
/* Use the methods of PutField to map between Serializable fields
 * and actual fields of a Serializable class.
 */

public abstract ObjectOutputStream.PutField putFields() throws IOException;