Java Code Examples for java.io.ObjectOutputStream#writeFields()

The following examples show how to use java.io.ObjectOutputStream#writeFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Permissions.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Default fields.
 */
/*
 * Writes the contents of the permsMap field out as a Hashtable for
 * serialization compatibility with earlier releases. allPermission
 * unchanged.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Don't call out.defaultWriteObject()

    // Copy perms into a Hashtable
    Hashtable<Class<?>, PermissionCollection> perms =
        new Hashtable<>(permsMap.size()*2); // no sync; estimate
    synchronized (this) {
        perms.putAll(permsMap);
    }

    // Write out serializable fields
    ObjectOutputStream.PutField pfields = out.putFields();

    pfields.put("allPermission", allPermission); // no sync; staleness OK
    pfields.put("perms", perms);
    out.writeFields();
}
 
Example 2
Source File: BigInteger.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
     * 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 3
Source File: Permissions.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Default fields.
 */
/*
 * Writes the contents of the permsMap field out as a Hashtable for
 * serialization compatibility with earlier releases. allPermission
 * unchanged.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Don't call out.defaultWriteObject()

    // Copy perms into a Hashtable
    Hashtable<Class<?>, PermissionCollection> perms =
        new Hashtable<>(permsMap.size()*2); // no sync; estimate
    synchronized (this) {
        perms.putAll(permsMap);
    }

    // Write out serializable fields
    ObjectOutputStream.PutField pfields = out.putFields();

    pfields.put("allPermission", allPermission); // no sync; staleness OK
    pfields.put("perms", perms);
    out.writeFields();
}
 
Example 4
Source File: RelationNotification.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: RelationTypeSupport.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * 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 6
Source File: NumericValueExp.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 7
Source File: DocumentImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example 8
Source File: RoleUnresolved.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serializes a {@link RoleUnresolved} 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("myRoleName", roleName);
    fields.put("myRoleValue", roleValue);
    fields.put("myPbType", problemType);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
  }
}
 
Example 9
Source File: Role.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 10
Source File: ServicePermission.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData "permissions" field (a Vector containing the ServicePermissions).
 */
/*
 * 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 11
Source File: Notification.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * 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 12
Source File: VetoableChangeSupport.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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 13
Source File: CryptoPermissions.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: PackagePermission.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private synchronized void writeObject(ObjectOutputStream out) throws IOException {
	Hashtable<String, PackagePermission> hashtable = new Hashtable<String, PackagePermission>(permissions);
	ObjectOutputStream.PutField pfields = out.putFields();
	pfields.put("permissions", hashtable);
	pfields.put("all_allowed", all_allowed);
	pfields.put("filterPermissions", filterPermissions);
	out.writeFields();
}
 
Example 15
Source File: CoreDocumentImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables for backward
 * compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables
    Hashtable<Node, Hashtable<String, UserDataRecord>> nud = null;
    if (nodeUserData != null) {
        nud = new Hashtable<>();
        for (Map.Entry<Node, Map<String, UserDataRecord>> e : nodeUserData.entrySet()) {
            //e.getValue() will not be null since an entry is always put with a non-null value
            nud.put(e.getKey(), new Hashtable<>(e.getValue()));
        }
    }

    Hashtable<String, Node> ids = (identifiers == null)? null : new Hashtable<>(identifiers);
    Hashtable<Node, Integer> nt = (nodeTable == null)? null : new Hashtable<>(nodeTable);

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("docType", docType);
    pf.put("docElement", docElement);
    pf.put("fFreeNLCache", fFreeNLCache);
    pf.put("encoding", encoding);
    pf.put("actualEncoding", actualEncoding);
    pf.put("version", version);
    pf.put("standalone", standalone);
    pf.put("fDocumentURI", fDocumentURI);

    //userData is the original name. It has been changed to nodeUserData, refer to the corrsponding @serialField
    pf.put("userData", nud);
    pf.put("identifiers", ids);
    pf.put("changes", changes);
    pf.put("allowGrammarAccess", allowGrammarAccess);
    pf.put("errorChecking", errorChecking);
    pf.put("ancestorChecking", ancestorChecking);
    pf.put("xmlVersionChanged", xmlVersionChanged);
    pf.put("documentNumber", documentNumber);
    pf.put("nodeCounter", nodeCounter);
    pf.put("nodeTable", nt);
    pf.put("xml11Version", xml11Version);
    out.writeFields();
}
 
Example 16
Source File: ObjectName.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Serializes an {@link ObjectName} to an {@link ObjectOutputStream}.
 * @serialData <ul>
 *               <li>In the current serial form (value of property
 *                   <code>jmx.serial.form</code> differs from
 *                   <code>1.0</code>): the string
 *                   &quot;&lt;domain&gt;:&lt;properties&gt;&lt;wild&gt;&quot;,
 *                   where: <ul>
 *                            <li>&lt;domain&gt; represents the domain part
 *                                of the {@link ObjectName}</li>
 *                            <li>&lt;properties&gt; represents the list of
 *                                properties, as returned by
 *                                {@link #getKeyPropertyListString}
 *                            <li>&lt;wild&gt; is empty if not
 *                                <code>isPropertyPattern</code>, or
 *                                is the character "<code>*</code>" if
 *                                this <code>isPropertyPattern</code>
 *                                and &lt;properties&gt; is empty, or
 *                                is "<code>,*</code>" if
 *                                <code>isPropertyPattern</code> and
 *                                &lt;properties&gt; is not empty.
 *                            </li>
 *                          </ul>
 *                   The intent is that this string could be supplied
 *                   to the {@link #ObjectName(String)} constructor to
 *                   produce an equivalent {@link ObjectName}.
 *               </li>
 *               <li>In the old serial form (value of property
 *                   <code>jmx.serial.form</code> is
 *                   <code>1.0</code>): &lt;domain&gt; &lt;propertyList&gt;
 *                   &lt;propertyListString&gt; &lt;canonicalName&gt;
 *                   &lt;pattern&gt; &lt;propertyPattern&gt;,
 *                   where: <ul>
 *                            <li>&lt;domain&gt; represents the domain part
 *                                of the {@link ObjectName}</li>
 *                            <li>&lt;propertyList&gt; is the
 *                                {@link Hashtable} that contains all the
 *                                pairs (key,value) for this
 *                                {@link ObjectName}</li>
 *                            <li>&lt;propertyListString&gt; is the
 *                                {@link String} representation of the
 *                                list of properties in any order (not
 *                                mandatorily a canonical representation)
 *                                </li>
 *                            <li>&lt;canonicalName&gt; is the
 *                                {@link String} containing this
 *                                {@link ObjectName}'s canonical name</li>
 *                            <li>&lt;pattern&gt; is a boolean which is
 *                                <code>true</code> if this
 *                                {@link ObjectName} contains a pattern</li>
 *                            <li>&lt;propertyPattern&gt; is a boolean which
 *                                is <code>true</code> if this
 *                                {@link ObjectName} contains a pattern in
 *                                the list of properties</li>
 *                          </ul>
 *               </li>
 *             </ul>
 */
private void writeObject(ObjectOutputStream out)
        throws IOException {

  if (compat)
  {
    // Serializes this instance in the old serial form
    // Read CR 6441274 before making any changes to this code
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("domain", _canonicalName.substring(0, _domain_length));
    fields.put("propertyList", getKeyPropertyList());
    fields.put("propertyListString", getKeyPropertyListString());
    fields.put("canonicalName", _canonicalName);
    fields.put("pattern", (_domain_pattern || _property_list_pattern));
    fields.put("propertyPattern", _property_list_pattern);
    out.writeFields();
  }
  else
  {
    // Serializes this instance in the new serial form
    //
    out.defaultWriteObject();
    out.writeObject(getSerializedNameString());
  }
}
 
Example 17
Source File: Support_GetPutFieldsDefaulted.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private void writeObject(ObjectOutputStream oos) throws IOException {
    putField = oos.putFields();
    // Do not put anything into putField so that the get methods
    // will have to use default values.
    oos.writeFields();
}
 
Example 18
Source File: DescriptorSupport.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 19
Source File: DescriptorSupport.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
Source File: XPathException.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Writes "cause" field to the stream.
 * The cause is got from the parent class.
 *
 * @param out stream used for serialization.
 * @throws IOException thrown by <code>ObjectOutputStream</code>
 *
 */
private void writeObject(ObjectOutputStream out)
        throws IOException
{
    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("cause", (Throwable) super.getCause());
    out.writeFields();
}