Java Code Examples for java.io.ObjectOutputStream.putFields()

The following are Jave code examples for showing how to use putFields() 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: ModelMBeanConstructorInfo.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link ModelMBeanConstructorInfo} 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("consDescriptor", consDescriptor);
    fields.put("currClass", currClass);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 2
Project: jdk8u-jdk   File: XMLParseException.java   View Source Code Vote up 6 votes
/**
 * Serializes an {@link XMLParseException} 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("msgStr", getMessage());
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 3
Project: openjdk-jdk10   File: ModelMBeanOperationInfo.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link ModelMBeanOperationInfo} 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("operationDescriptor", operationDescriptor);
    fields.put("currClass", currClass);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 4
Project: OpenJSharp   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 5
Project: OpenJSharp   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 6
Project: openjdk-jdk10   File: ModelMBeanConstructorInfo.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link ModelMBeanConstructorInfo} 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("consDescriptor", consDescriptor);
    fields.put("currClass", currClass);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 7
Project: jdk8u-jdk   File: GetPutFieldTrees.java   View Source Code Vote up 6 votes
private void writeObject(ObjectOutputStream out) throws IOException {
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("z", z);
    fields.put("b", b);
    fields.put("c", c);
    fields.put("s", s);
    fields.put("i", i);
    fields.put("f", f);
    fields.put("j", j);
    fields.put("d", d);
    fields.put("str", str);
    fields.put("parent", parent);
    fields.put("left", left);
    fields.put("right", right);
    out.writeFields();
}
 
Example 8
Project: OpenJSharp   File: DelegationPermission.java   View Source Code Vote up 6 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.size());

    synchronized (this) {
        permissions.addAll(perms);
    }

    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("permissions", permissions);
    out.writeFields();
}
 
Example 9
Project: openjdk-jdk10   File: PropertyPermission.java   View Source Code Vote up 6 votes
/**
 * @serialData Default fields.
 */
/*
 * Writes the contents of the perms field out as a Hashtable for
 * serialization compatibility with earlier releases. all_allowed
 * unchanged.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Don't call out.defaultWriteObject()

    // Copy perms into a Hashtable
    Hashtable<String, Permission> permissions =
        new Hashtable<>(perms.size()*2);
    permissions.putAll(perms);

    // Write out serializable fields
    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("all_allowed", all_allowed);
    pfields.put("permissions", permissions);
    out.writeFields();
}
 
Example 10
Project: OpenJSharp   File: XMLParseException.java   View Source Code Vote up 6 votes
/**
 * Serializes an {@link XMLParseException} 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("msgStr", getMessage());
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 11
Project: jdk8u-jdk   File: Role.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link Role} 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("myName", name);
    fields.put("myObjNameList", objectNameList);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 12
Project: OpenJSharp   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 13
Project: jdk8u-jdk   File: ModelMBeanInfoSupport.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link ModelMBeanInfoSupport} 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("modelMBeanDescriptor", modelMBeanDescriptor);
        fields.put("mmbAttributes", modelMBeanAttributes);
        fields.put("mmbConstructors", modelMBeanConstructors);
        fields.put("mmbNotifications", modelMBeanNotifications);
        fields.put("mmbOperations", modelMBeanOperations);
        fields.put("currClass", currClass);
        out.writeFields();
    } else {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
    }
}
 
Example 14
Project: openjdk-jdk10   File: RoleResult.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link RoleResult} 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("myRoleList", roleList);
    fields.put("myRoleUnresList", unresolvedRoleList);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 15
Project: jdk8u-jdk   File: Notification.java   View Source Code Vote up 6 votes
/**
 * Serializes a {@link Notification} 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("type", type);
        fields.put("sequenceNumber", sequenceNumber);
        fields.put("timeStamp", timeStamp);
        fields.put("userData", userData);
        fields.put("message", message);
        fields.put("source", source);
        out.writeFields();
    } else {
        // Serializes this instance in the new serial form
        //
        out.defaultWriteObject();
    }
}
 
Example 16
Project: jdk8u-jdk   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 17
Project: OpenJSharp   File: CryptoPermissions.java   View Source Code Vote up 5 votes
private void writeObject(ObjectOutputStream s) throws IOException {
    Hashtable<String,PermissionCollection> permTable =
            new Hashtable<>(perms);
    ObjectOutputStream.PutField fields = s.putFields();
    fields.put("perms", permTable);
    s.writeFields();
}
 
Example 18
Project: openjdk-jdk10   File: UnresolvedPermissionCollection.java   View Source Code Vote up 5 votes
/**
 * @serialData Default field.
 */
/*
 * Writes the contents of the perms field out as a Hashtable
 * in which the values are Vectors for
 * serialization compatibility with earlier releases.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Don't call out.defaultWriteObject()

    // Copy perms into a Hashtable
    Hashtable<String, Vector<UnresolvedPermission>> permissions =
        new Hashtable<>(perms.size()*2);

    // Convert each entry (List) into a Vector
    Set<Map.Entry<String, List<UnresolvedPermission>>> set = perms.entrySet();
    for (Map.Entry<String, List<UnresolvedPermission>> e : set) {
        // Convert list into Vector
        List<UnresolvedPermission> list = e.getValue();
        Vector<UnresolvedPermission> vec = new Vector<>(list);

        // Add to Hashtable being serialized
        permissions.put(e.getKey(), vec);
    }

    // Write out serializable fields
    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("permissions", permissions);
    out.writeFields();
}
 
Example 19
Project: jdk8u-jdk   File: DescriptorSupport.java   View Source Code Vote up 4 votes
/**
 * Serializes a {@link DescriptorSupport} to an {@link ObjectOutputStream}.
 */
/* If you set jmx.serial.form to "1.2.0" or "1.2.1", then we are
   bug-compatible with those versions.  Specifically, field names
   are forced to lower-case before being written.  This
   contradicts the spec, which, though it does not mention
   serialization explicitly, does say that the case of field names
   is preserved.  But in 1.2.0 and 1.2.1, this requirement was not
   met.  Instead, field names in the descriptor map were forced to
   lower case.  Those versions expect this to have happened to a
   descriptor they deserialize and e.g. getFieldValue will not
   find a field whose name is spelt with a different case.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
    ObjectOutputStream.PutField fields = out.putFields();
    boolean compat = "1.0".equals(serialForm);
    if (compat)
        fields.put("currClass", currClass);

    /* Purge the field "targetObject" from the DescriptorSupport before
     * serializing since the referenced object is typically not
     * serializable.  We do this here rather than purging the "descriptor"
     * variable below because that HashMap doesn't do case-insensitivity.
     * See CR 6332962.
     */
    SortedMap<String, Object> startMap = descriptorMap;
    if (startMap.containsKey("targetObject")) {
        startMap = new TreeMap<String, Object>(descriptorMap);
        startMap.remove("targetObject");
    }

    final HashMap<String, Object> descriptor;
    if (compat || "1.2.0".equals(serialForm) ||
            "1.2.1".equals(serialForm)) {
        descriptor = new HashMap<String, Object>();
        for (Map.Entry<String, Object> entry : startMap.entrySet())
            descriptor.put(entry.getKey().toLowerCase(), entry.getValue());
    } else
        descriptor = new HashMap<String, Object>(startMap);

    fields.put("descriptor", descriptor);
    out.writeFields();
}
 
Example 20
Project: openjdk-jdk10   File: DescriptorSupport.java   View Source Code Vote up 4 votes
/**
 * Serializes a {@link DescriptorSupport} to an {@link ObjectOutputStream}.
 */
/* If you set jmx.serial.form to "1.2.0" or "1.2.1", then we are
   bug-compatible with those versions.  Specifically, field names
   are forced to lower-case before being written.  This
   contradicts the spec, which, though it does not mention
   serialization explicitly, does say that the case of field names
   is preserved.  But in 1.2.0 and 1.2.1, this requirement was not
   met.  Instead, field names in the descriptor map were forced to
   lower case.  Those versions expect this to have happened to a
   descriptor they deserialize and e.g. getFieldValue will not
   find a field whose name is spelt with a different case.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
    ObjectOutputStream.PutField fields = out.putFields();
    boolean compat = "1.0".equals(serialForm);
    if (compat)
        fields.put("currClass", currClass);

    /* Purge the field "targetObject" from the DescriptorSupport before
     * serializing since the referenced object is typically not
     * serializable.  We do this here rather than purging the "descriptor"
     * variable below because that HashMap doesn't do case-insensitivity.
     * See CR 6332962.
     */
    SortedMap<String, Object> startMap = descriptorMap;
    if (startMap.containsKey("targetObject")) {
        startMap = new TreeMap<String, Object>(descriptorMap);
        startMap.remove("targetObject");
    }

    final HashMap<String, Object> descriptor;
    if (compat || "1.2.0".equals(serialForm) ||
            "1.2.1".equals(serialForm)) {
        descriptor = new HashMap<String, Object>();
        for (Map.Entry<String, Object> entry : startMap.entrySet())
            descriptor.put(entry.getKey().toLowerCase(), entry.getValue());
    } else
        descriptor = new HashMap<String, Object>(startMap);

    fields.put("descriptor", descriptor);
    out.writeFields();
}