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:com.alfaariss.oa.util.saml2.idp.SAML2IDP.java

/**
 * Deal with internally stored metadata stuff
 *
 * @param oOutputStream//from   w  w  w. ja va2  s.  com
 */
private void writeObject(ObjectOutputStream oOutputStream) throws java.io.IOException {
    try {
        if (_sMetadata == null) {
            // Create the MetadataXMLObject so we can extract the XML-string from it:
            if (_oMetadataXMLObject == null && _oMetadataProvider != null) {
                _oMetadataXMLObject = _oMetadataProvider.getMetadata();
            }

            if (_oMetadataXMLObject != null) {
                StringWriter oSW = new StringWriter();
                XMLObjectHelper.marshallToWriter(_oMetadataXMLObject, oSW);
                _sMetadata = oSW.toString();
            }
        }
    } catch (MarshallingException e) {
        _oLogger.error("Exception when marshalling XMLObject to Writer for SAML2IDP, dropping metadata: "
                + e.getMessage());
        return;
    } catch (MetadataProviderException e) {
        _oLogger.error("Exception when serializing and retrieving Metadata for SAML2IDP '" + _sID + "':"
                + e.getMessage());
        throw new IOException(e);
    }

    // Do its thing:
    oOutputStream.defaultWriteObject();
}

From source file:org.mule.MessagePropertiesContext.java

/**
 * Check for properties that can't be serialized
 *//* w  w  w  . j a  v a 2s .  c  om*/
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    for (PropertyScope scope : new PropertyScope[] { PropertyScope.INBOUND, PropertyScope.OUTBOUND }) {
        for (Map.Entry<String, Object> entry : scopedMap.get(scope).entrySet()) {
            Object value = entry.getValue();
            if (value != null && !(value instanceof Serializable)) {
                String message = String.format(
                        "Unable to serialize the %s message property %s, which is of type %s ", scope,
                        entry.getKey(), value);
                logger.error(message);
                throw new IOException(message);
            }
        }
    }
    if (invocationMap instanceof UndefinedInvocationPropertiesMap) {
        for (Map.Entry<String, Object> entry : invocationMap.entrySet()) {
            Object value = entry.getValue();
            if (value != null && !(value instanceof Serializable)) {
                String message = String.format(
                        "Unable to serialize the invocation message property %s, which is of type %s ",
                        entry.getKey(), value);
                logger.error(message);
                throw new IOException(message);
            }
        }
    }
    out.defaultWriteObject();
}

From source file:org.mule.DefaultMuleMessage.java

private void writeObject(ObjectOutputStream out) throws Exception {
    out.defaultWriteObject();
    if (payload instanceof Serializable) {
        out.writeBoolean(true);//from   w w  w .ja  v  a  2 s.  c o  m
        out.writeObject(payload);
    } else {
        out.writeBoolean(false);
        byte[] serializablePayload = getPayloadAsBytes();
        out.writeInt(serializablePayload.length);
        out.write(serializablePayload);
    }
    out.writeObject(serializeAttachments(inboundAttachments));
    out.writeObject(serializeAttachments(outboundAttachments));

    // TODO: we don't serialize the originalPayload for now
}

From source file:org.saiku.service.olap.OlapQueryService.java

private void writeObject(ObjectOutputStream stream) throws IOException {

    serializableQueries = new HashMap<>();
    for (Map.Entry<String, IQuery> entry : queries.entrySet()) {
        serializableQueries.put(entry.getKey(), new QuerySerializer(entry.getValue()).createXML());
    }//from   www  . j a  v a2s  .co  m
    stream.defaultWriteObject();
}

From source file:ConcurrentReferenceHashMap.java

/**
 * Save the state of the <tt>ConcurrentReferenceHashMap</tt> instance to a
 * stream (i.e., serialize it)./*from w  w  w  . j  av a2s  . c  o  m*/
 * @param s the stream
 * @serialData
 * 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 {
    s.defaultWriteObject();

    for (int k = 0; k < segments.length; ++k) {
        Segment<K, V> seg = segments[k];
        seg.lock();
        try {
            HashEntry<K, V>[] tab = seg.table;
            for (int i = 0; i < tab.length; ++i) {
                for (HashEntry<K, V> e = tab[i]; e != null; e = e.next) {
                    K key = e.key();
                    if (key == null) // Skip GC'd keys
                        continue;

                    s.writeObject(key);
                    s.writeObject(e.value());
                }
            }
        } finally {
            seg.unlock();
        }
    }
    s.writeObject(null);
    s.writeObject(null);
}

From source file:org.hibernate.internal.SessionFactoryImpl.java

/**
 * Custom serialization hook defined by Java spec. Used when the factory is
 * directly serialized/*  w ww .  ja v  a  2 s  . c o m*/
 * 
 * @param out
 *            The stream into which the object is being serialized.
 * 
 * @throws IOException
 *             Can be thrown by the stream
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    LOG.debugf("Serializing: %s", uuid);
    out.defaultWriteObject();
    LOG.trace("Serialized");
}

From source file:org.archive.modules.CrawlURI.java

private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    stream.writeObject((data == null || data.isEmpty()) ? null : data);
}

From source file:org.apache.beehive.controls.runtime.bean.ControlBean.java

/**
 * Implementation of the Java serialization writeObject method
 *//*w ww  . jav  a2  s .c om*/
private synchronized void writeObject(ObjectOutputStream oos) throws IOException {
    if (_control != null) {
        //
        // If the implementation class is marked as transient/stateless, then reset the
        // reference to it prior to serialization.  A new instance will be created by
        // ensureControl() upon first use after deserialization.
        // If the implementation class is not transient, then invoke the ImplInitializer
        // resetServices method to reset all contextual service references to null, as
        // contextual services should never be serializated and always reassociated on 
        // deserialization.
        //
        ControlImplementation implAnnot = (ControlImplementation) _implClass
                .getAnnotation(ControlImplementation.class);
        assert implAnnot != null;
        if (implAnnot.isTransient()) {
            _control = null;
        } else {
            getImplInitializer().resetServices(this, _control);
            _hasServices = false;
        }
    }

    oos.defaultWriteObject();
}

From source file:alice.tuprolog.lib.OOLibrary.java

/**
 * handling writeObject method is necessary in order to make the library
 * serializable, 'nullyfing' eventually objects registered in maps
 *//*  w  w w  . j  av  a  2s . co  m*/
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    HashMap<String, Object> bak00 = currentObjects;
    IdentityHashMap<Object, Struct> bak01 = currentObjects_inverse;
    try {
        currentObjects = null;
        currentObjects_inverse = null;
        out.defaultWriteObject();
    } catch (IOException ex) {
        currentObjects = bak00;
        currentObjects_inverse = bak01;
        throw new IOException();
    }
    currentObjects = bak00;
    currentObjects_inverse = bak01;
}

From source file:com.sworddance.util.perf.LapTimer.java

private void writeObject(ObjectOutputStream out) throws IOException {
    boolean skipCheck = this.home == null;

    // check to see if this LapTimer was received remotely.
    // if its homeVMID was not set then this JVM/ClassLoader
    // is created it and is sending it out.
    if (skipCheck) {
        synchronized (vmid) {
            this.home = new Id(vmid, remotingCounter++);
        }//from  ww  w .  j  a v a 2 s. com
    }
    if (skipCheck || LapTimer.receivedLaptimers.remove(this.home) == null) {
        LapTimer.sentLaptimers.put(this.home, this);
    }
    boolean restart = this.isRunning();
    if (restart) {
        this.beginNewLap("XMIT");
        //            this.pause(); TODO how to handle staying on same machine?
    }
    out.writeBoolean(restart);
    out.defaultWriteObject();
}