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

The following are Jave code examples for showing how to use writeFields() 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: 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 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: 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 4
Project: jdk8u-jdk   File: RoleUnresolved.java   View Source Code Vote up 6 votes
/**
 * 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 5
Project: OpenJSharp   File: Permissions.java   View Source Code Vote up 6 votes
/**
 * @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 6
Project: OpenJSharp   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 7
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 8
Project: OpenJSharp   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 = (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 9
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 10
Project: openjdk-jdk10   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 11
Project: OpenJSharp   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 12
Project: OpenJSharp   File: SocketPermission.java   View Source Code Vote up 6 votes
/**
 * @serialData "permissions" field (a Vector containing the SocketPermissions).
 */
/*
 * 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<SocketPermission> permissions = new Vector<>(perms.size());

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

    ObjectOutputStream.PutField pfields = out.putFields();
    pfields.put("permissions", permissions);
    out.writeFields();
}
 
Example 13
Project: jdk8u-jdk   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);
    synchronized (this) {
        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 14
Project: interview-question-code   File: Session.java   View Source Code Vote up 5 votes
/** 重写序列化函数*/
private void writeObject(ObjectOutputStream out) throws IOException{
    ObjectOutputStream.PutField putFields = out.putFields();
    putFields.put("sessionId", Base64.encode(sessionId.getBytes()));
    putFields.put("expired", expired);
    System.out.println("self unserialization " + this.getClass());
    out.writeFields();
}
 
Example 15
Project: jdk8u-jdk   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: OpenJSharp   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: VetoableChangeSupport.java   View Source Code Vote up 5 votes
/**
 * @serialData Null terminated list of {@code VetoableChangeListeners}.
 * <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 18
Project: OpenJSharp   File: InetAddress.java   View Source Code Vote up 5 votes
private void writeObject (ObjectOutputStream s) throws
                    IOException {
    if (getClass().getClassLoader() != null) {
        throw new SecurityException ("invalid address type");
    }
    PutField pf = s.putFields();
    pf.put("hostName", holder().getHostName());
    pf.put("address", holder().getAddress());
    pf.put("family", holder().getFamily());
    s.writeFields();
}
 
Example 19
Project: openjdk-jdk10   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 20
Project: OpenJSharp   File: Container.java   View Source Code Vote up 4 votes
/**
 * Serializes this <code>Container</code> to the specified
 * <code>ObjectOutputStream</code>.
 * <ul>
 *    <li>Writes default serializable fields to the stream.</li>
 *    <li>Writes a list of serializable ContainerListener(s) as optional
 *        data. The non-serializable ContainerListner(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</code> is written.</li>
 * </ul>
 *
 * @param s the <code>ObjectOutputStream</code> to write
 * @serialData <code>null</code> terminated sequence of 0 or more pairs;
 *   the pair consists of a <code>String</code> and <code>Object</code>;
 *   the <code>String</code> indicates the type of object and
 *   is one of the following:
 *   <code>containerListenerK</code> indicating an
 *     <code>ContainerListener</code> object;
 *   the <code>Container</code>'s <code>FocusTraversalPolicy</code>,
 *     or <code>null</code>
 *
 * @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);
    }
}