Example usage for java.io ObjectOutputStream writeObject

List of usage examples for java.io ObjectOutputStream writeObject

Introduction

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

Prototype

public final void writeObject(Object obj) throws IOException 

Source Link

Document

Write the specified object to the ObjectOutputStream.

Usage

From source file:fr.ortolang.diffusion.notification.NotificationServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void throwEvent(String fromObject, String throwedBy, String objectType, String eventType,
        Map<String, String> arguments) throws NotificationServiceException {
    try {//from w w w .  ja  va 2s.co m
        Message message = context.createMessage();
        message.setStringProperty(OrtolangEvent.DATE, OrtolangEvent.getEventDateFormatter().format(new Date()));
        message.setStringProperty(OrtolangEvent.THROWED_BY, throwedBy);
        message.setStringProperty(OrtolangEvent.FROM_OBJECT, fromObject);
        message.setStringProperty(OrtolangEvent.OBJECT_TYPE, objectType);
        message.setStringProperty(OrtolangEvent.TYPE, eventType);
        if (arguments != null && arguments instanceof Serializable) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(arguments);
            oos.close();
            message.setStringProperty(OrtolangEvent.ARGUMENTS, Base64.encodeBase64String(baos.toByteArray()));
        }
        context.createProducer().send(notificationTopic, message);

    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "unable to throw event", e);
        throw new NotificationServiceException("unable to throw event", e);
    }
}

From source file:com.jaspersoft.jasperserver.core.util.TolerantObjectWrapper.java

/**
 * tests whether an object is serializable
 *
 * return boolean representing if it is serializable
 *
 * *//*from   w  w  w.j  a va2  s.  c  om*/
private boolean testIsSerializable(Object obj) throws IOException {

    NullOutputStream nos = new NullOutputStream();
    ObjectOutputStream oos = null;

    try {
        oos = new ObjectOutputStream(nos);
        oos.writeObject(obj);
        oos.close();
        nos.close();

    } catch (Exception err) {
        return false;
    }
    return true;
}

From source file:com.impetus.kundera.property.accessor.ObjectAccessor.java

@Override
public final byte[] toBytes(Object o) {

    try {/*from   w  ww . j  av a  2s  .c  o  m*/
        if (o != null) {
            if (o instanceof byte[]) {
                return (byte[]) o;
            }

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(o);
            oos.close();
            return baos.toByteArray();
        }
    } catch (IOException e) {
        throw new PropertyAccessException(e);
    }
    return null;
}

From source file:jhttpp2.Jhttpp2Launcher.java

public boolean saveServerSettings() {
    storeServerProperties();/*  w  w w.j a va 2 s.  c  om*/
    ObjectOutputStream file;
    try {
        file = new ObjectOutputStream(new FileOutputStream(DATA_FILE));
        file.writeObject(server.getWildcardDictionary());
        file.writeObject(server.getURLActions());
        file.close();
        return true;
    } catch (Exception e) {
        log.warn("Was not able to save the settings", e);
    }
    return false;

}

From source file:com.hp.autonomy.hod.sso.HodAuthenticationTest.java

private <T extends Serializable> T writeAndReadObject(final T object)
        throws IOException, ClassNotFoundException {
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(object);
    objectOutputStream.close();//from  www. j a  va2s .  c om

    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
            byteArrayOutputStream.toByteArray());
    final ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);

    //noinspection unchecked
    return (T) objectInputStream.readObject();
}

From source file:org.apache.servicemix.http.endpoints.SerializedMarshaler.java

/**
 * Unmarshal the XML content to the specified output stream. This method is unmarshaling XML into the Spring 
 * <a href="http://www.springframework.org/docs/api/org/springframework/remoting/support/RemoteInvocationResult.html">
 * RemoteInvocationResult</a> object. Below is an example of the XML expected by this method:
 * /*from w  w w  .  j  ava2 s .c  o  m*/
 * <pre>
 * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
 * &lt;org.springframework.remoting.support.RemoteInvocationResult&gt;
 *   &lt;value class=&quot;com.example.foo.bar.Baz&quot;&gt;
 *     &lt;firstName&gt;myfirstname&lt;/firstName&gt;
 *     &lt;lastName&gt;mylastname&lt;/lastName&gt;
 *     &lt;phone&gt;12312312&lt;/phone&gt;
 *   &lt;/value&gt;
 * &lt;/org.springframework.remoting.support.RemoteInvocationResult&gt;
 * </pre>
 * 
 * @param os -
 *            output stream to unmarshal to
 * @param content -
 *            XML source
 * @throws TransformerException
 * @throws IOException
 */
private void unmarshal(OutputStream os, Source content) throws TransformerException, IOException {
    SourceTransformer transform = new SourceTransformer();
    XStream xstream = new XStream(new DomDriver());
    String result = transform.toString(content);

    if (log.isDebugEnabled()) {
        log.debug("Remote invocation result: " + result);
    }

    Object obj = xstream.fromXML(result);
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(obj);
}

From source file:org.cyclop.test.AbstractTestCase.java

public byte[] serialize(Object obj) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(obj);
    out.close();//from   w w w .  ja va  2  s  . c  om
    byte[] serialized = bout.toByteArray();
    assertNotNull(serialized);
    return serialized;
}

From source file:com.collabnet.ccf.pi.qc.QCReaderOutputWriter.java

public Object[] processXMLDocuments(Object data, String fileName) {

    //List<List<Document>> retObj=new ArrayList<List<Document>>();
    //List<Document> incomingObj= new ArrayList<Document>();
    Document incomingDoc = (Document) data;
    incomingDoc = changeForQCWriter(incomingDoc);
    //retObj.add(incomingObj);

    try {//from  w w  w  . j  a  v a  2s. co  m
        FileOutputStream f = new FileOutputStream(fileName);
        ObjectOutputStream s = new ObjectOutputStream(f);

        s.writeObject(incomingDoc);
    } catch (IOException e) {
        System.out.println("File handling exception" + e);
    }

    Object[] result = { incomingDoc };
    return result;
}

From source file:captureplugin.drivers.defaultdriver.ParamEntry.java

/**
 * Save data to Stream/*  ww  w  . j a  v a2s . c  o  m*/
 * @param out save to this stream
 * @throws IOException during save operation
 */
public void writeData(ObjectOutputStream out) throws IOException {
    out.writeInt(2);
    out.writeObject(mName);
    out.writeObject(mParam);
    out.writeBoolean(mEnabled);
}

From source file:dkpro.similarity.algorithms.wikipedia.measures.WikiLinkCache.java

/**
 * Serializes the cache and saves it to the given file.
 *
 * @param file the file to save the cache to
 * @throws IOException//w  w  w.jav a2s  .c o m
 * @throws FileNotFoundException
 * @throws IOException if the file cannot be read
 */
public void serializeObject(Object o, File file) throws FileNotFoundException, IOException {
    logger.info("Writing cache to file: " + file.getAbsolutePath());
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
    oos.writeObject(o);
    oos.flush();
    oos.close();
}