Example usage for java.io ObjectOutputStream writeInt

List of usage examples for java.io ObjectOutputStream writeInt

Introduction

In this page you can find the example usage for java.io ObjectOutputStream writeInt.

Prototype

public void writeInt(int val) throws IOException 

Source Link

Document

Writes a 32 bit int.

Usage

From source file:CopyOnWriteArrayList.java

/**
 * Save the state of the list to a stream (i.e., serialize it).
 * @param s /*from   www  .j  av  a2s  .c om*/
 * @throws java.io.IOException 
 * 
 * @serialData The length of the array backing the list is emitted (int),
 *             followed by all of its elements (each an Object) in the
 *             proper order.
 */
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
    // Write out element count, and any hidden stuff
    s.defaultWriteObject();

    Object[] elementData = array();
    // Write out array length
    s.writeInt(elementData.length);

    // Write out all elements in the proper order.
    for (int i = 0; i < elementData.length; i++)
        s.writeObject(elementData[i]);
}

From source file:CopyOnWriteArrayList.java

/**
 * Save the state of the list to a stream (i.e., serialize it).
 *
 * @serialData The length of the array backing the list is emitted
 *               (int), followed by all of its elements (each an Object)
 *               in the proper order./*  w w  w. j a v a 2s  .  c  o  m*/
 * @param s the stream
 */
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {

    // Write out element count, and any hidden stuff
    s.defaultWriteObject();

    Object[] elements = getArray();
    int len = elements.length;
    // Write out array length
    s.writeInt(len);

    // Write out all elements in the proper order.
    for (int i = 0; i < len; i++)
        s.writeObject(elements[i]);
}

From source file:ConcurrentReaderHashMap.java

/**
 * Save the state of the <tt>ConcurrentReaderHashMap</tt> 
 * instance to a stream (i.e.,//  w ww . j a v a2  s. c o  m
 * serialize it).
 *
 * @serialData The <i>capacity</i> of the 
 * ConcurrentReaderHashMap (the length of the
 * bucket array) is emitted (int), followed  by the
 * <i>size</i> of the ConcurrentReaderHashMap (the number of key-value
 * mappings), followed by the key (Object) and value (Object)
 * for each key-value mapping represented by the ConcurrentReaderHashMap
 * The key-value mappings are emitted in no particular order.
 */

private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException {
    // Write out the threshold, loadfactor, and any hidden stuff
    s.defaultWriteObject();

    // Write out number of buckets
    s.writeInt(table.length);

    // Write out size (number of Mappings)
    s.writeInt(count);

    // Write out keys and values (alternating)
    for (int index = table.length - 1; index >= 0; index--) {
        Entry entry = table[index];

        while (entry != null) {
            s.writeObject(entry.key);
            s.writeObject(entry.value);
            entry = entry.next;
        }
    }
}

From source file:ConcurrentReaderHashMap.java

/**
 * Save the state of the <tt>ConcurrentReaderHashMap</tt> instance to a
 * stream (i.e., serialize it)./*from  w  ww.j a  va  2s .  co  m*/
 * @param s 
 * @throws IOException 
 * 
 * @serialData The <i>capacity</i> of the ConcurrentReaderHashMap (the
 *             length of the bucket array) is emitted (int), followed by the
 *             <i>size</i> of the ConcurrentReaderHashMap (the number of
 *             key-value mappings), followed by the key (Object) and value
 *             (Object) for each key-value mapping represented by the
 *             ConcurrentReaderHashMap The key-value mappings are emitted in
 *             no particular order.
 */
private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException {
    // Write out the threshold, loadfactor, and any hidden stuff
    s.defaultWriteObject();

    // Write out number of buckets
    s.writeInt(table.length);

    // Write out size (number of Mappings)
    s.writeInt(count);

    // Write out keys and values (alternating)
    for (int index = table.length - 1; index >= 0; index--) {
        Entry entry = table[index];

        while (entry != null) {
            s.writeObject(entry.key);
            s.writeObject(entry.value);
            entry = entry.next;
        }
    }
}

From source file:edu.umd.cs.marmoset.modelClasses.TestOutcome.java

private void writeObject(ObjectOutputStream stream) throws IOException {
    truncateLongTestResult();/*  w  w w.ja  v a 2  s  .  c o m*/
    stream.writeInt(serialMinorVersion);
    stream.defaultWriteObject();
}

From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();/*from w ww  . ja va  2 s  .  c  o  m*/
    out.writeInt(_size);
    Listable cur = _head.next();
    while (cur != null) {
        out.writeObject(cur.value());
        cur = cur.next();
    }
}

From source file:com.projity.pm.resource.EnterpriseResource.java

private void writeObject(ObjectOutputStream s) throws IOException {
    s.defaultWriteObject();//from  w w w  . j  a  v a 2 s .  c  o  m
    hasKey.serialize(s);
    costRateTables.serialize(s);
    customFields.serialize(s);
    s.writeInt(hasAssignments.getSchedulingType());
    s.writeBoolean(hasAssignments.isEffortDriven());
    availabilityTable.serialize(s);
}

From source file:ddf.catalog.data.impl.MetacardImpl.java

/**
 * Serializes this {@link MetacardImpl} instance.
 *
 * @param stream the {@link ObjectOutputStream} that contains the object to be serialized
 * @throws IOException//  w  w  w.ja  v a 2 s .c  om
 * @serialData First, all non-transient fields are written out by the default Java serialization
 * implementation ( {@link ObjectOutputStream#defaultWriteObject()}) . Next, the
 * {@link MetacardType} is written out as a {@link MetacardTypeImpl}. Then the
 * <i>number</i> of {@code Attribute} objects is written as an {@code int}. After
 * the number of objects, each {@code Attribute} object is written out.
 * <p>
 * <p>
 * The MetacardType object is written out as a {@link MetacardTypeImpl} object
 * because {@link MetacardTypeImpl} is a class that is part of the DDF API and is
 * guaranteed to be on the classpath when this object is deserialized. Secondly, the
 * {@link MetacardTypeImpl} has a trusted serialization implementation where the
 * object's logical representation is serialized.
 * </p>
 */
private void writeObject(ObjectOutputStream stream) throws IOException {

    /*
     * defaultWriteObject() is invoked for greater flexibility and compatibility. See the
     * *Serialization Note* in MetacardImpl's class Javadoc.
     */
    stream.defaultWriteObject();

    /*
     * Cannot allow unknown implementations of MetacardType to be serialized. Must convert them
     * to our implementation to guarantee it is serializing the logical representation and not
     * the physical representation.
     */
    if (type instanceof MetacardTypeImpl) {
        stream.writeObject(type);
    } else {
        MetacardTypeImpl mt = new MetacardTypeImpl(type.getName(), type.getAttributeDescriptors());
        stream.writeObject(mt);
    }

    if (map != null) {
        stream.writeInt(map.size());

        for (Attribute attribute : this.map.values()) {
            stream.writeObject(attribute);
        }
    } else {
        if (wrappedMetacard != null && wrappedMetacard.getMetacardType() != null) {

            MetacardType metacardType = wrappedMetacard.getMetacardType();

            List<Attribute> attributes = new ArrayList<Attribute>();

            if (metacardType.getAttributeDescriptors() == null) {
                // no descriptors, means no attributes can be defined.
                // no attributes defined, means no attributes written to
                // disk
                stream.writeInt(0);
            } else {

                for (AttributeDescriptor ad : metacardType.getAttributeDescriptors()) {

                    Attribute attribute = wrappedMetacard.getAttribute(ad.getName());

                    if (attribute != null) {
                        attributes.add(attribute);
                    }
                }

                // Must loop again because the size of the attributes list
                // is not known until list has been fully populated.
                stream.writeInt(attributes.size());

                for (Attribute attribute : attributes) {
                    stream.writeObject(attribute);
                }
            }
        }
    }

}

From source file:net.di2e.ecdr.commons.CDRMetacard.java

private void writeObject(ObjectOutputStream stream) throws IOException {

    /*/*w ww  .j av a2s. com*/
     * defaultWriteObject() is invoked for greater flexibility and compatibility. See the *Serialization Note* in
     * class Javadoc.
     */
    stream.defaultWriteObject();

    /*
     * Cannot allow unknown implementations of MetacardType to be serialized. Must convert them to our
     * implementation to guarantee it is serializing the logical representation and not the physical representation.
     */
    if (type instanceof MetacardTypeImpl) {
        stream.writeObject(type);
    } else {
        MetacardTypeImpl mt = new MetacardTypeImpl(type.getName(), type.getAttributeDescriptors());
        stream.writeObject(mt);
    }

    if (map != null) {
        stream.writeInt(map.size());

        for (Attribute attribute : this.map.values()) {
            stream.writeObject(attribute);
        }
    } else {
        if (wrappedMetacard != null && wrappedMetacard.getMetacardType() != null) {

            MetacardType metacardType = wrappedMetacard.getMetacardType();

            List<Attribute> attributes = new ArrayList<Attribute>();

            if (metacardType.getAttributeDescriptors() == null) {
                // no descriptors, means no attributes can be defined.
                // no attributes defined, means no attributes written to
                // disk
                stream.writeInt(0);
            } else {

                for (AttributeDescriptor ad : metacardType.getAttributeDescriptors()) {

                    Attribute attribute = wrappedMetacard.getAttribute(ad.getName());

                    if (attribute != null) {
                        attributes.add(attribute);
                    }
                }

                // Must loop again because the size of the attributes list
                // is not known until list has been fully populated.
                stream.writeInt(attributes.size());

                for (Attribute attribute : attributes) {
                    stream.writeObject(attribute);
                }
            }
        }
    }

}

From source file:ConcurrentHashMap.java

/**
 * Save the state of the <tt>ConcurrentHashMap</tt> instance to a stream
 * (i.e., serialize it)./*from  w w  w.j a va  2 s.c o m*/
 * @param s 
 * @throws IOException 
 * 
 * @serialData An estimate of the table size, followed by the key (Object)
 *             and value (Object) for each key-value mapping, followed by a
 *             null pair. The key-value mappings are emitted in no
 *             particular order.
 */
private void writeObject(java.io.ObjectOutputStream s) throws IOException {
    // Write out the loadfactor, and any hidden stuff
    s.defaultWriteObject();

    // Write out capacity estimate. It is OK if this
    // changes during the write, since it is only used by
    // readObject to set initial capacity, to avoid needless resizings.

    int cap;
    synchronized (segments[0]) {
        cap = table.length;
    }
    s.writeInt(cap);

    // Write out keys and values (alternating)
    for (int k = 0; k < segments.length; ++k) {
        Segment seg = segments[k];
        Entry[] tab;
        synchronized (seg) {
            tab = table;
        }
        for (int i = k; i < tab.length; i += segments.length) {
            for (Entry e = tab[i]; e != null; e = e.next) {
                s.writeObject(e.key);
                s.writeObject(e.value);
            }
        }
    }

    s.writeObject(null);
    s.writeObject(null);
}