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

The following are Jave code examples for showing how to use write() 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: SimpleTimeZone.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 2
Project: incubator-netbeans   File: ClassLoadedCommand.java   View Source Code Vote up 6 votes
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeUTF(className);

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

    if (classFileBytes != null) {
        out.writeInt(classFileBytes.length);
        out.write(classFileBytes);
        classFileBytes = null;
    } else {
        out.writeInt(0);
    }

    out.writeBoolean(threadInCallGraph);
}
 
Example 3
Project: OpenJSharp   File: CertificateRevokedException.java   View Source Code Vote up 6 votes
/**
 * 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);
    }
}
 
Example 4
Project: OpenJSharp   File: SimpleTimeZone.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 5
Project: BUbiNG   File: WorkbenchVirtualizer.java   View Source Code Vote up 6 votes
private void writeMetadata(final ObjectOutputStream oos) throws IOException {
	oos.writeLong(byteArrayDiskQueues.size);
	oos.writeLong(byteArrayDiskQueues.appendPointer);
	oos.writeLong(byteArrayDiskQueues.used);
	oos.writeLong(byteArrayDiskQueues.allocated);
	oos.writeInt(byteArrayDiskQueues.buffers.size());
	oos.writeInt(byteArrayDiskQueues.key2QueueData.size());
	final ObjectIterator<Reference2ObjectMap.Entry<Object, QueueData>> fastIterator = byteArrayDiskQueues.key2QueueData.reference2ObjectEntrySet().fastIterator();
	for(int i = byteArrayDiskQueues.key2QueueData.size(); i-- != 0;) {
		final Reference2ObjectMap.Entry<Object, QueueData> next = fastIterator.next();
		final VisitState visitState = (VisitState)next.getKey();
		// TODO: temporary, to catch serialization bug
		if (visitState == null) {
			LOGGER.error("Map iterator returned null key");
			continue;
		}
		else if (visitState.schemeAuthority == null) LOGGER.error("Map iterator returned visit state with null schemeAuthority");
		else Util.writeVByte(visitState.schemeAuthority.length, oos);
		oos.write(visitState.schemeAuthority);
		oos.writeObject(next.getValue());
	}

	oos.close();
}
 
Example 6
Project: openjdk-jdk10   File: CertificateRevokedException.java   View Source Code Vote up 6 votes
/**
 * 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);
    }
}
 
Example 7
Project: openjdk-jdk10   File: StubIORImpl.java   View Source Code Vote up 5 votes
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]);
    }
}
 
Example 8
Project: incubator-netbeans   File: GetClassFileBytesResponse.java   View Source Code Vote up 5 votes
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(classBytes.length);

    for (int i = 0; i < classBytes.length; i++) {
        if (classBytes[i] == null) {
            out.writeInt(0);
        } else {
            out.writeInt(classBytes[i].length);
            out.write(classBytes[i]);
        }
    }
}
 
Example 9
Project: OpenJSharp   File: StubIORImpl.java   View Source Code Vote up 5 votes
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]);
    }
}
 
Example 10
Project: OpenJSharp   File: X509V1CertImpl.java   View Source Code Vote up 5 votes
private synchronized void writeObject(ObjectOutputStream stream)
    throws IOException {
    try {
        stream.write(getEncoded());
    } catch (CertificateEncodingException e) {
        throw new IOException("getEncoded failed: " + e.getMessage());
    }
}
 
Example 11
Project: openjdk-jdk10   File: X509V1CertImpl.java   View Source Code Vote up 5 votes
private synchronized void writeObject(ObjectOutputStream stream)
    throws IOException {
    try {
        stream.write(getEncoded());
    } catch (CertificateEncodingException e) {
        throw new IOException("getEncoded failed: " + e.getMessage());
    }
}
 
Example 12
Project: incubator-netbeans   File: InstrumentMethodGroupData.java   View Source Code Vote up 4 votes
void writeObject(ObjectOutputStream out) throws IOException {
    if (instrMethodClasses == null) {
        out.writeInt(0);

        return;
    }

    out.writeInt(nClasses);

    for (int i = 0; i < nClasses; i++) {
        out.writeUTF(instrMethodClasses[i]);
        out.writeInt(instrMethodClassLoaderIds[i]);
    }

    out.writeInt(nMethods);

    if (instrMethodLeaf != null) {
        out.write(1);

        for (int i = 0; i < nMethods; i++) {
            out.writeBoolean(instrMethodLeaf[i]);
        }
    } else {
        out.write(0);
    }

    out.writeInt(addInfo);

    for (int i = 0; i < nClasses; i++) {
        if (replacementClassFileBytes[i] == null) {
            out.writeInt(0);
        } else {
            out.writeInt(replacementClassFileBytes[i].length);
            out.write(replacementClassFileBytes[i]);
        }
    }

    instrMethodClasses = null;
    instrMethodClassLoaderIds = null;
    instrMethodLeaf = null;
    replacementClassFileBytes = null;
}
 
Example 13
Project: openjdk-jdk10   File: MBeanInfo.java   View Source Code Vote up 4 votes
/**
 * 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);
    }
}
 
Example 14
Project: incubator-netbeans   File: ThreadLivenessStatusResponse.java   View Source Code Vote up 4 votes
void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(status.length);
    out.write(status);
}
 
Example 15
Project: jdk8u-jdk   File: MBeanInfo.java   View Source Code Vote up 4 votes
/**
 * 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);
    }
}
 
Example 16
Project: jdk8u-jdk   File: MBeanFeatureInfo.java   View Source Code Vote up 4 votes
/**
 * 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);
    }
}
 
Example 17
Project: OpenJSharp   File: MBeanFeatureInfo.java   View Source Code Vote up 4 votes
/**
 * 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);
    }
}
 
Example 18
Project: hadoop   File: JavaKeyStoreProvider.java   View Source Code Vote up 4 votes
private void writeObject(ObjectOutputStream out) throws IOException {
  byte[] serialized = metadata.serialize();
  out.writeInt(serialized.length);
  out.write(serialized);
}
 
Example 19
Project: datatree   File: Tree.java   View Source Code Vote up 3 votes
/**
 * Serializes this node into the target stream.
 * 
 * @param out
 *            target stream
 * 
 * @throws IOException
 *             any I/O exception
 */
private void writeObject(ObjectOutputStream out) throws IOException {
	out.defaultWriteObject();
	byte[] bytes = JavaBuiltin.serialize(value, meta, true);
	out.writeInt(bytes.length);
	out.write(bytes);
}
 
Example 20
Project: BUbiNG   File: Util.java   View Source Code Vote up 2 votes
/** Writes a byte array prefixed by its length encoded using vByte.
 *
 * @param a the array to be written.
 * @param s the stream where the array should be written.
 */
public final static void writeByteArray(final byte[] a, final ObjectOutputStream s) throws IOException {
	writeVByte(a.length, s);
	s.write(a);
}