java.io.ObjectOutputStream#write ( )源码实例Demo

下面列出了java.io.ObjectOutputStream#write ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bytecoder   文件: SimpleTimeZone.java
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * @serialData We write out two formats, a JDK 1.1 compatible format, using
 * {@code DOW_IN_MONTH_MODE} rules, in the required section, followed
 * by the full rules, in packed format, in the optional section.  The
 * optional section will be ignored by JDK 1.1 code upon stream in.
 * <p> Contents of the optional section: The length of a byte array is
 * emitted (int); this is 4 as of this release. The byte array of the given
 * length is emitted. The contents of the byte array are the true values of
 * the fields {@code startDay}, {@code startDayOfWeek},
 * {@code endDay}, and {@code endDayOfWeek}.  The values of these
 * fields in the required section are approximate values suited to the rule
 * mode {@code DOW_IN_MONTH_MODE}, which is the only mode recognized by
 * JDK 1.1.
 */
@java.io.Serial
private void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Construct a binary rule
    byte[] rules = packRules();
    int[] times = packTimes();

    // Convert to 1.1 FCS rules.  This step may cause us to lose information.
    makeRulesCompatible();

    // Write out the 1.1 FCS rules
    stream.defaultWriteObject();

    // Write out the binary rules in the optional data area of the stream.
    stream.writeInt(rules.length);
    stream.write(rules);
    stream.writeObject(times);

    // Recover the original rules.  This recovers the information lost
    // by makeRulesCompatible.
    unpackRules(rules);
    unpackTimes(times);
}
 
源代码2 项目: visualvm   文件: EventBufferDumpedCommand.java
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(bufSize);
    out.writeBoolean(buffer != null);
    if (buffer != null) {
        Deflater compressor = new Deflater();
        // for small buffers, the compressed size can be somewhat larger than the original  
        byte[] compressedBytes = new byte[bufSize + 32]; 
        int compressedSize;
        
        compressor.setInput(buffer,startPos,bufSize);
        compressor.finish();
        compressedSize = compressor.deflate(compressedBytes);
        out.writeInt(compressedSize);
        out.write(compressedBytes,0,compressedSize);
    } else {
        out.writeUTF(eventBufferFileName);
    }
}
 
源代码3 项目: jdk1.8-source-analysis   文件: SimpleTimeZone.java
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * @serialData We write out two formats, a JDK 1.1 compatible format, using
 * <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed
 * by the full rules, in packed format, in the optional section.  The
 * optional section will be ignored by JDK 1.1 code upon stream in.
 * <p> Contents of the optional section: The length of a byte array is
 * emitted (int); this is 4 as of this release. The byte array of the given
 * length is emitted. The contents of the byte array are the true values of
 * the fields <code>startDay</code>, <code>startDayOfWeek</code>,
 * <code>endDay</code>, and <code>endDayOfWeek</code>.  The values of these
 * fields in the required section are approximate values suited to the rule
 * mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by
 * JDK 1.1.
 */
private void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Construct a binary rule
    byte[] rules = packRules();
    int[] times = packTimes();

    // Convert to 1.1 FCS rules.  This step may cause us to lose information.
    makeRulesCompatible();

    // Write out the 1.1 FCS rules
    stream.defaultWriteObject();

    // Write out the binary rules in the optional data area of the stream.
    stream.writeInt(rules.length);
    stream.write(rules);
    stream.writeObject(times);

    // Recover the original rules.  This recovers the information lost
    // by makeRulesCompatible.
    unpackRules(rules);
    unpackTimes(times);
}
 
源代码4 项目: openjdk-8-source   文件: SimpleTimeZone.java
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * @serialData We write out two formats, a JDK 1.1 compatible format, using
 * <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed
 * by the full rules, in packed format, in the optional section.  The
 * optional section will be ignored by JDK 1.1 code upon stream in.
 * <p> Contents of the optional section: The length of a byte array is
 * emitted (int); this is 4 as of this release. The byte array of the given
 * length is emitted. The contents of the byte array are the true values of
 * the fields <code>startDay</code>, <code>startDayOfWeek</code>,
 * <code>endDay</code>, and <code>endDayOfWeek</code>.  The values of these
 * fields in the required section are approximate values suited to the rule
 * mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by
 * JDK 1.1.
 */
private void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Construct a binary rule
    byte[] rules = packRules();
    int[] times = packTimes();

    // Convert to 1.1 FCS rules.  This step may cause us to lose information.
    makeRulesCompatible();

    // Write out the 1.1 FCS rules
    stream.defaultWriteObject();

    // Write out the binary rules in the optional data area of the stream.
    stream.writeInt(rules.length);
    stream.write(rules);
    stream.writeObject(times);

    // Recover the original rules.  This recovers the information lost
    // by makeRulesCompatible.
    unpackRules(rules);
    unpackTimes(times);
}
 
源代码5 项目: openjdk-8   文件: SimpleTimeZone.java
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * @serialData We write out two formats, a JDK 1.1 compatible format, using
 * <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed
 * by the full rules, in packed format, in the optional section.  The
 * optional section will be ignored by JDK 1.1 code upon stream in.
 * <p> Contents of the optional section: The length of a byte array is
 * emitted (int); this is 4 as of this release. The byte array of the given
 * length is emitted. The contents of the byte array are the true values of
 * the fields <code>startDay</code>, <code>startDayOfWeek</code>,
 * <code>endDay</code>, and <code>endDayOfWeek</code>.  The values of these
 * fields in the required section are approximate values suited to the rule
 * mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by
 * JDK 1.1.
 */
private void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Construct a binary rule
    byte[] rules = packRules();
    int[] times = packTimes();

    // Convert to 1.1 FCS rules.  This step may cause us to lose information.
    makeRulesCompatible();

    // Write out the 1.1 FCS rules
    stream.defaultWriteObject();

    // Write out the binary rules in the optional data area of the stream.
    stream.writeInt(rules.length);
    stream.write(rules);
    stream.writeObject(times);

    // Recover the original rules.  This recovers the information lost
    // by makeRulesCompatible.
    unpackRules(rules);
    unpackTimes(times);
}
 
/**
 * Serialize this {@code CertificateRevokedException} instance.
 *
 * @serialData the size of the extensions map (int), followed by all of
 * the extensions in the map, in no particular order. For each extension,
 * the following data is emitted: the OID String (Object), the criticality
 * flag (boolean), the length of the encoded extension value byte array
 * (int), and the encoded extension value bytes.
 */
private void writeObject(ObjectOutputStream oos) throws IOException {
    // Write out the non-transient fields
    // (revocationDate, reason, authority)
    oos.defaultWriteObject();

    // Write out the size (number of mappings) of the extensions map
    oos.writeInt(extensions.size());

    // For each extension in the map, the following are emitted (in order):
    // the OID String (Object), the criticality flag (boolean), the length
    // of the encoded extension value byte array (int), and the encoded
    // extension value byte array. The extensions themselves are emitted
    // in no particular order.
    for (Map.Entry<String, Extension> entry : extensions.entrySet()) {
        Extension ext = entry.getValue();
        oos.writeObject(ext.getId());
        oos.writeBoolean(ext.isCritical());
        byte[] extVal = ext.getValue();
        oos.writeInt(extVal.length);
        oos.write(extVal);
    }
}
 
/**
 * Serialize this {@code CertificateRevokedException} instance.
 *
 * @serialData the size of the extensions map (int), followed by all of
 * the extensions in the map, in no particular order. For each extension,
 * the following data is emitted: the OID String (Object), the criticality
 * flag (boolean), the length of the encoded extension value byte array
 * (int), and the encoded extension value bytes.
 */
private void writeObject(ObjectOutputStream oos) throws IOException {
    // Write out the non-transient fields
    // (revocationDate, reason, authority)
    oos.defaultWriteObject();

    // Write out the size (number of mappings) of the extensions map
    oos.writeInt(extensions.size());

    // For each extension in the map, the following are emitted (in order):
    // the OID String (Object), the criticality flag (boolean), the length
    // of the encoded extension value byte array (int), and the encoded
    // extension value byte array. The extensions themselves are emitted
    // in no particular order.
    for (Map.Entry<String, Extension> entry : extensions.entrySet()) {
        Extension ext = entry.getValue();
        oos.writeObject(ext.getId());
        oos.writeBoolean(ext.isCritical());
        byte[] extVal = ext.getValue();
        oos.writeInt(extVal.length);
        oos.write(extVal);
    }
}
 
源代码8 项目: hottub   文件: SimpleTimeZone.java
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * @serialData We write out two formats, a JDK 1.1 compatible format, using
 * <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed
 * by the full rules, in packed format, in the optional section.  The
 * optional section will be ignored by JDK 1.1 code upon stream in.
 * <p> Contents of the optional section: The length of a byte array is
 * emitted (int); this is 4 as of this release. The byte array of the given
 * length is emitted. The contents of the byte array are the true values of
 * the fields <code>startDay</code>, <code>startDayOfWeek</code>,
 * <code>endDay</code>, and <code>endDayOfWeek</code>.  The values of these
 * fields in the required section are approximate values suited to the rule
 * mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by
 * JDK 1.1.
 */
private void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Construct a binary rule
    byte[] rules = packRules();
    int[] times = packTimes();

    // Convert to 1.1 FCS rules.  This step may cause us to lose information.
    makeRulesCompatible();

    // Write out the 1.1 FCS rules
    stream.defaultWriteObject();

    // Write out the binary rules in the optional data area of the stream.
    stream.writeInt(rules.length);
    stream.write(rules);
    stream.writeObject(times);

    // Recover the original rules.  This recovers the information lost
    // by makeRulesCompatible.
    unpackRules(rules);
    unpackTimes(times);
}
 
源代码9 项目: jdk8u-dev-jdk   文件: SimpleTimeZone.java
/**
 * Save the state of this object to a stream (i.e., serialize it).
 *
 * @serialData We write out two formats, a JDK 1.1 compatible format, using
 * <code>DOW_IN_MONTH_MODE</code> rules, in the required section, followed
 * by the full rules, in packed format, in the optional section.  The
 * optional section will be ignored by JDK 1.1 code upon stream in.
 * <p> Contents of the optional section: The length of a byte array is
 * emitted (int); this is 4 as of this release. The byte array of the given
 * length is emitted. The contents of the byte array are the true values of
 * the fields <code>startDay</code>, <code>startDayOfWeek</code>,
 * <code>endDay</code>, and <code>endDayOfWeek</code>.  The values of these
 * fields in the required section are approximate values suited to the rule
 * mode <code>DOW_IN_MONTH_MODE</code>, which is the only mode recognized by
 * JDK 1.1.
 */
private void writeObject(ObjectOutputStream stream)
     throws IOException
{
    // Construct a binary rule
    byte[] rules = packRules();
    int[] times = packTimes();

    // Convert to 1.1 FCS rules.  This step may cause us to lose information.
    makeRulesCompatible();

    // Write out the 1.1 FCS rules
    stream.defaultWriteObject();

    // Write out the binary rules in the optional data area of the stream.
    stream.writeInt(rules.length);
    stream.write(rules);
    stream.writeObject(times);

    // Recover the original rules.  This recovers the information lost
    // by makeRulesCompatible.
    unpackRules(rules);
    unpackTimes(times);
}
 
源代码10 项目: visualvm   文件: MethodNamesResponse.java
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(packedData.length);
    out.write(packedData);
    out.writeInt(packedArrayOffsets.length);

    for (int i = 0; i < packedArrayOffsets.length; i++) {
        out.writeInt(packedArrayOffsets[i]);
    }

    packedData = null;
    packedArrayOffsets = null;
}
 
源代码11 项目: reladomo   文件: ObjectWithSerializationError.java
private void writeObject(ObjectOutputStream out) throws IOException
{
    byte[] bytes = this.contents.getBytes("ISO8859_1");
    out.writeInt(bytes.length);
    if (this.exceptionThrown)
    {
        out.write(bytes);
    }
    else
    {
        out.write(bytes, 0, bytes.length / 2);
        this.exceptionThrown = true;
        throw new IOException();
    }
}
 
源代码12 项目: hottub   文件: StubIORImpl.java
public  void doWrite( ObjectOutputStream stream )
    throws IOException
{
    // write the IOR to the ObjectOutputStream
    stream.writeInt(typeData.length);
    stream.write(typeData);
    stream.writeInt(profileTags.length);
    for (int i = 0; i < profileTags.length; i++) {
        stream.writeInt(profileTags[i]);
        stream.writeInt(profileData[i].length);
        stream.write(profileData[i]);
    }
}
 
源代码13 项目: Java8CN   文件: MBeanFeatureInfo.java
/**
 * Serializes an {@link MBeanFeatureInfo} to an {@link ObjectOutputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is serialized as follows.
 * <p>
 * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
 * is called first to serialize the object except the field {@code descriptor}
 * which is declared as transient. The field {@code descriptor} is serialized
 * as follows:
 *     <ul>
 *     <li>If {@code descriptor} is an instance of the class
 *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
 *        write(int val)} is called to write a byte with the value {@code 1},
 *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
 *        is called twice to serialize the field names and the field values of the
 *        {@code descriptor}, respectively as a {@code String[]} and an
 *        {@code Object[]};</li>
 *     <li>Otherwise, the method {@link ObjectOutputStream#write write(int val)}
 * is called to write a byte with the value {@code 0}, then the method
 * {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
 * to serialize directly the field {@code descriptor}.
 *     </ul>
 *
 * @since 1.6
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor != null &&
        descriptor.getClass() == ImmutableDescriptor.class) {

        out.write(1);

        final String[] names = descriptor.getFieldNames();

        out.writeObject(names);
        out.writeObject(descriptor.getFieldValues(names));
    } else {
        out.write(0);

        out.writeObject(descriptor);
    }
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: MBeanInfo.java
/**
 * Serializes an {@link MBeanInfo} to an {@link ObjectOutputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is serialized as follows.
 * <p>
 * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
 * is called first to serialize the object except the field {@code descriptor}
 * which is declared as transient. The field {@code descriptor} is serialized
 * as follows:
 *     <ul>
 *     <li> If {@code descriptor} is an instance of the class
 *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
 *        write(int val)} is called to write a byte with the value {@code 1},
 *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
 *        is called twice to serialize the field names and the field values of the
 *        {@code descriptor}, respectively as a {@code String[]} and an
 *        {@code Object[]};</li>
 *     <li> Otherwise, the method {@link ObjectOutputStream#write write(int val)}
 *        is called to write a byte with the value {@code 0}, then the method
 *        {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
 *        to serialize the field {@code descriptor} directly.
 *     </ul>
 *
 * @since 1.6
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor.getClass() == ImmutableDescriptor.class) {
        out.write(1);

        final String[] names = descriptor.getFieldNames();

        out.writeObject(names);
        out.writeObject(descriptor.getFieldValues(names));
    } else {
        out.write(0);

        out.writeObject(descriptor);
    }
}
 
源代码15 项目: hottub   文件: MBeanFeatureInfo.java
/**
 * Serializes an {@link MBeanFeatureInfo} to an {@link ObjectOutputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is serialized as follows.
 * <p>
 * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
 * is called first to serialize the object except the field {@code descriptor}
 * which is declared as transient. The field {@code descriptor} is serialized
 * as follows:
 *     <ul>
 *     <li>If {@code descriptor} is an instance of the class
 *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
 *        write(int val)} is called to write a byte with the value {@code 1},
 *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
 *        is called twice to serialize the field names and the field values of the
 *        {@code descriptor}, respectively as a {@code String[]} and an
 *        {@code Object[]};</li>
 *     <li>Otherwise, the method {@link ObjectOutputStream#write write(int val)}
 * is called to write a byte with the value {@code 0}, then the method
 * {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
 * to serialize directly the field {@code descriptor}.
 *     </ul>
 *
 * @since 1.6
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor != null &&
        descriptor.getClass() == ImmutableDescriptor.class) {

        out.write(1);

        final String[] names = descriptor.getFieldNames();

        out.writeObject(names);
        out.writeObject(descriptor.getFieldValues(names));
    } else {
        out.write(0);

        out.writeObject(descriptor);
    }
}
 
源代码16 项目: openjdk-jdk8u   文件: MBeanInfo.java
/**
 * Serializes an {@link MBeanInfo} to an {@link ObjectOutputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is serialized as follows.
 * <p>
 * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
 * is called first to serialize the object except the field {@code descriptor}
 * which is declared as transient. The field {@code descriptor} is serialized
 * as follows:
 *     <ul>
 *     <li> If {@code descriptor} is an instance of the class
 *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
 *        write(int val)} is called to write a byte with the value {@code 1},
 *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
 *        is called twice to serialize the field names and the field values of the
 *        {@code descriptor}, respectively as a {@code String[]} and an
 *        {@code Object[]};</li>
 *     <li> Otherwise, the method {@link ObjectOutputStream#write write(int val)}
 *        is called to write a byte with the value {@code 0}, then the method
 *        {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
 *        to serialize the field {@code descriptor} directly.
 *     </ul>
 *
 * @since 1.6
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor.getClass() == ImmutableDescriptor.class) {
        out.write(1);

        final String[] names = descriptor.getFieldNames();

        out.writeObject(names);
        out.writeObject(descriptor.getFieldValues(names));
    } else {
        out.write(0);

        out.writeObject(descriptor);
    }
}
 
private void writeObject( final ObjectOutputStream out ) throws IOException{
  out.write( length );
  out.write( value , start , length );
}
 
源代码18 项目: jdk8u60   文件: MBeanInfo.java
/**
 * Serializes an {@link MBeanInfo} to an {@link ObjectOutputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is serialized as follows.
 * <p>
 * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
 * is called first to serialize the object except the field {@code descriptor}
 * which is declared as transient. The field {@code descriptor} is serialized
 * as follows:
 *     <ul>
 *     <li> If {@code descriptor} is an instance of the class
 *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
 *        write(int val)} is called to write a byte with the value {@code 1},
 *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
 *        is called twice to serialize the field names and the field values of the
 *        {@code descriptor}, respectively as a {@code String[]} and an
 *        {@code Object[]};</li>
 *     <li> Otherwise, the method {@link ObjectOutputStream#write write(int val)}
 *        is called to write a byte with the value {@code 0}, then the method
 *        {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
 *        to serialize the field {@code descriptor} directly.
 *     </ul>
 *
 * @since 1.6
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor.getClass() == ImmutableDescriptor.class) {
        out.write(1);

        final String[] names = descriptor.getFieldNames();

        out.writeObject(names);
        out.writeObject(descriptor.getFieldValues(names));
    } else {
        out.write(0);

        out.writeObject(descriptor);
    }
}
 
源代码19 项目: jdk8u60   文件: MBeanFeatureInfo.java
/**
 * Serializes an {@link MBeanFeatureInfo} to an {@link ObjectOutputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is serialized as follows.
 * <p>
 * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
 * is called first to serialize the object except the field {@code descriptor}
 * which is declared as transient. The field {@code descriptor} is serialized
 * as follows:
 *     <ul>
 *     <li>If {@code descriptor} is an instance of the class
 *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
 *        write(int val)} is called to write a byte with the value {@code 1},
 *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
 *        is called twice to serialize the field names and the field values of the
 *        {@code descriptor}, respectively as a {@code String[]} and an
 *        {@code Object[]};</li>
 *     <li>Otherwise, the method {@link ObjectOutputStream#write write(int val)}
 * is called to write a byte with the value {@code 0}, then the method
 * {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
 * to serialize directly the field {@code descriptor}.
 *     </ul>
 *
 * @since 1.6
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor != null &&
        descriptor.getClass() == ImmutableDescriptor.class) {

        out.write(1);

        final String[] names = descriptor.getFieldNames();

        out.writeObject(names);
        out.writeObject(descriptor.getFieldValues(names));
    } else {
        out.write(0);

        out.writeObject(descriptor);
    }
}
 
源代码20 项目: JDKSourceCode1.8   文件: MBeanFeatureInfo.java
/**
 * Serializes an {@link MBeanFeatureInfo} to an {@link ObjectOutputStream}.
 * @serialData
 * For compatibility reasons, an object of this class is serialized as follows.
 * <p>
 * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
 * is called first to serialize the object except the field {@code descriptor}
 * which is declared as transient. The field {@code descriptor} is serialized
 * as follows:
 *     <ul>
 *     <li>If {@code descriptor} is an instance of the class
 *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
 *        write(int val)} is called to write a byte with the value {@code 1},
 *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
 *        is called twice to serialize the field names and the field values of the
 *        {@code descriptor}, respectively as a {@code String[]} and an
 *        {@code Object[]};</li>
 *     <li>Otherwise, the method {@link ObjectOutputStream#write write(int val)}
 * is called to write a byte with the value {@code 0}, then the method
 * {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
 * to serialize directly the field {@code descriptor}.
 *     </ul>
 *
 * @since 1.6
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor != null &&
        descriptor.getClass() == ImmutableDescriptor.class) {

        out.write(1);

        final String[] names = descriptor.getFieldNames();

        out.writeObject(names);
        out.writeObject(descriptor.getFieldValues(names));
    } else {
        out.write(0);

        out.writeObject(descriptor);
    }
}