Example usage for java.io ObjectOutputStream defaultWriteObject

List of usage examples for java.io ObjectOutputStream defaultWriteObject

Introduction

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

Prototype

public void defaultWriteObject() throws IOException 

Source Link

Document

Write the non-static and non-transient fields of the current class to this stream.

Usage

From source file:msi.gama.outputs.layers.charts.StandardXYItemRenderer.java

/**
 * Provides serialization support.//from w ww.j  a v a  2 s  .  c o m
 *
 * @param stream
 *            the output stream.
 *
 * @throws IOException
 *             if there is an I/O error.
 */
private void writeObject(final ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    SerialUtilities.writeShape(this.legendLine, stream);
}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Provides serialization support./*from   www  .  j ava 2s .c o m*/
 *
 * @param stream  the output stream.
 *
 * @throws IOException  if there is an I/O error.
 */
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    stream.writeInt(this.lineWidth);
    stream.writeInt(this.shapeSize);
}

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/* www . j  a v a 2s. co m*/
 * @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:IntHashMap.java

/**
 * Save the state of the <tt>HashMap</tt> instance to a stream (i.e.,
 * serialize it)./*from w ww. ja v  a  2s .  c om*/
 * 
 * @param s
 *            The ObjectOutputStream
 * @throws IOException
 * 
 * @serialData The <i>capacity</i> of the HashMap (the length of the bucket
 *             array) is emitted (int), followed by the <i>size</i> of the
 *             HashMap (the number of key-value mappings), followed by the
 *             key (Object) and value (Object) for each key-value mapping
 *             represented by the HashMap The key-value mappings are emitted
 *             in the order that they are returned by
 *             <tt>entrySet().iterator()</tt>.
 * 
 */
private 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(size);

    // Write out keys and values (alternating)
    for (Iterator i = entrySet().iterator(); i.hasNext();) {
        Entry e = (Entry) i.next();
        s.writeInt(e.getKey());
        s.writeObject(e.getValue());
    }
}

From source file:IntHashMap.java

/**
 * Save the state of the <tt>HashMap</tt> instance to a stream (i.e., serialize it).
 * //from  www  .ja  v  a  2 s  .  c om
 * @param s
 *            The ObjectOutputStream
 * @throws IOException
 * 
 * @serialData The <i>capacity</i> of the HashMap (the length of the bucket array) is emitted
 *             (int), followed by the <i>size</i> of the HashMap (the number of key-value
 *             mappings), followed by the key (Object) and value (Object) for each key-value
 *             mapping represented by the HashMap The key-value mappings are emitted in the
 *             order that they are returned by <tt>entrySet().iterator()</tt>.
 * 
 */
private 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(size);

    // Write out keys and values (alternating)
    for (Iterator<Entry<V>> i = entrySet().iterator(); i.hasNext();) {
        Entry<V> e = i.next();
        s.writeInt(e.getKey());
        s.writeObject(e.getValue());
    }
}

From source file:org.apache.flink.cep.nfa.SharedBuffer.java

private void writeObject(ObjectOutputStream oos) throws IOException {
    DataOutputViewStreamWrapper target = new DataOutputViewStreamWrapper(oos);
    Map<SharedBufferEntry<K, V>, Integer> entryIDs = new HashMap<>();
    int totalEdges = 0;
    int entryCounter = 0;

    oos.defaultWriteObject();

    // number of pages
    oos.writeInt(pages.size());//from  ww w  .  j  a v  a  2 s. c o  m

    for (Map.Entry<K, SharedBufferPage<K, V>> pageEntry : pages.entrySet()) {
        SharedBufferPage<K, V> page = pageEntry.getValue();

        // key for the current page
        oos.writeObject(page.getKey());
        // number of page entries
        oos.writeInt(page.entries.size());

        for (Map.Entry<ValueTimeWrapper<V>, SharedBufferEntry<K, V>> sharedBufferEntry : page.entries
                .entrySet()) {
            // serialize the sharedBufferEntry
            SharedBufferEntry<K, V> sharedBuffer = sharedBufferEntry.getValue();

            // assign id to the sharedBufferEntry for the future serialization of the previous
            // relation
            entryIDs.put(sharedBuffer, entryCounter++);

            ValueTimeWrapper<V> valueTimeWrapper = sharedBuffer.getValueTime();

            valueSerializer.serialize(valueTimeWrapper.value, target);
            oos.writeLong(valueTimeWrapper.getTimestamp());

            int edges = sharedBuffer.edges.size();
            totalEdges += edges;

            oos.writeInt(sharedBuffer.referenceCounter);
        }
    }

    // write the edges between the shared buffer entries
    oos.writeInt(totalEdges);

    for (Map.Entry<K, SharedBufferPage<K, V>> pageEntry : pages.entrySet()) {
        SharedBufferPage<K, V> page = pageEntry.getValue();

        for (Map.Entry<ValueTimeWrapper<V>, SharedBufferEntry<K, V>> sharedBufferEntry : page.entries
                .entrySet()) {
            SharedBufferEntry<K, V> sharedBuffer = sharedBufferEntry.getValue();

            if (!entryIDs.containsKey(sharedBuffer)) {
                throw new RuntimeException("Could not find id for entry: " + sharedBuffer);
            } else {
                int id = entryIDs.get(sharedBuffer);

                for (SharedBufferEdge<K, V> edge : sharedBuffer.edges) {
                    // in order to serialize the previous relation we simply serialize the ids
                    // of the source and target SharedBufferEntry
                    if (edge.target != null) {
                        if (!entryIDs.containsKey(edge.getTarget())) {
                            throw new RuntimeException("Could not find id for entry: " + edge.getTarget());
                        } else {
                            int targetId = entryIDs.get(edge.getTarget());

                            oos.writeInt(id);
                            oos.writeInt(targetId);
                            oos.writeObject(edge.version);
                        }
                    } else {
                        oos.writeInt(id);
                        oos.writeInt(-1);
                        oos.writeObject(edge.version);
                    }
                }
            }
        }
    }
}

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

private void writeObject(ObjectOutputStream stream) throws IOException {

    /*//ww  w.j  a  va  2  s.  c o  m
     * 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:org.pentaho.reporting.engine.classic.core.Element.java

/**
 * A helper method that serializes the element object.
 *
 * @param stream//from w  w  w.java 2  s .  c  om
 *          the stream to which the element should be serialized.
 * @throws IOException
 *           if an IO error occured or a property was not serializable.
 */
private void writeObject(final ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    final ReportAttributeMap attributes = this.attributes;
    stream.writeLong(attributes.getChangeTracker());
    final String[] nameSpaces = attributes.getNameSpaces();
    stream.writeObject(nameSpaces);
    for (int i = 0; i < nameSpaces.length; i++) {
        final String nameSpace = nameSpaces[i];
        final String[] names = attributes.getNames(nameSpace);
        stream.writeObject(names);
        for (int j = 0; j < names.length; j++) {
            final String name = names[j];
            final Object attribute = attributes.getAttribute(nameSpace, name);

            final AttributeMetaData data = getMetaData().getAttributeDescription(nameSpace, name);
            if (data != null) {
                if (data.isTransient()) {
                    stream.writeByte(1);
                    continue;
                }

                if (attribute instanceof ResourceKey) {
                    final ResourceKey key = (ResourceKey) attribute;
                    final ResourceKey parent = key.getParent();
                    if (AttributeNames.Core.NAMESPACE.equals(nameSpace)
                            && (AttributeNames.Core.CONTENT_BASE.equals(name)
                                    || AttributeNames.Core.SOURCE.equals(name))) {
                        if (parent != null) {
                            // unwrap the content base attribute. After deserialization, the report assumes the bundle-location
                            // as content base, as the bundle will be gone.
                            if (isKeySerializable(parent)) {
                                stream.writeByte(0);
                                SerializerHelper.getInstance().writeObject(parent, stream);
                            } else {
                                stream.writeByte(1);
                            }
                        } else {
                            // great, the report was never part of a bundle. That makes life easier and the key should be
                            // safely serializable too.

                            if (isKeySerializable(key)) {
                                stream.writeByte(0);
                                SerializerHelper.getInstance().writeObject(key, stream);
                            } else {
                                stream.writeByte(1);
                            }
                        }
                    } else {
                        if ("Resource".equals(data.getValueRole()) || parent != null) {
                            stream.writeByte(0);
                            try {
                                final ResourceKey resourceKey = ResourceKeyUtils.embedResourceInKey(
                                        locateResourceManager(), key, key.getFactoryParameters());
                                SerializerHelper.getInstance().writeObject(resourceKey, stream);
                            } catch (ResourceException e) {
                                throw new IOException(
                                        "Failed to convert resource-key into byte-array key: " + e);
                            }
                        } else {
                            stream.writeByte(0);
                            SerializerHelper.getInstance().writeObject(attribute, stream);
                        }
                    }
                } else if (SerializerHelper.getInstance().isSerializable(attribute)) {
                    stream.writeByte(0);
                    SerializerHelper.getInstance().writeObject(attribute, stream);
                } else {
                    stream.writeByte(1);
                }
            } else if (attribute instanceof String) {
                stream.writeByte(0);
                SerializerHelper.getInstance().writeObject(attribute, stream);
            } else {
                stream.writeByte(1);
            }
        }
    }
}

From source file:CopyOnWriteArrayList.java

/**
 * Save the state of the list to a stream (i.e., serialize it).
 * @param s /* ww  w  .  j a  va  2  s.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.//from w  w  w. j a v  a2  s.com
 * @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]);
}