Example usage for java.io ObjectOutputStream close

List of usage examples for java.io ObjectOutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes the stream.

Usage

From source file:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java

/**
 * @throws IOException/* w  w  w. ja  v a  2s  .  c om*/
 * @see fr.hoteia.qalingo.core.dao.impl.EmailDao#saveEmail(Email email,
 *      MimeMessagePreparatorImpl mimeMessagePreparator)
 */
public void saveEmail(final Email email, final MimeMessagePreparatorImpl mimeMessagePreparator)
        throws IOException {
    Session session = (Session) em.getDelegate();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);

    oos.writeObject(mimeMessagePreparator);
    oos.flush();
    oos.close();
    bos.close();

    byte[] data = bos.toByteArray();

    Blob blob = Hibernate.getLobCreator(session).createBlob(data);

    email.setEmailContent(blob);

    saveOrUpdateEmail(email);
}

From source file:com.g3net.tool.ObjectUtils.java

/**
 * //from w  w  w.  j av  a  2s  . c  o  m
 * @param o   ???java??,???
 * @return     
 * @throws Exception
 */
public static byte[] serializeObject(Object o) throws Exception {
    ByteArrayOutputStream bos = null;
    ObjectOutputStream oos = null;
    if (o == null) {
        return null;
    }

    try {
        bos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(bos);
        oos.writeObject(o);
        oos.flush();
        return bos.toByteArray();
    } finally {
        if (oos != null) {
            oos.close();
        }
    }
}

From source file:com.ning.metrics.serialization.event.TestSmileEnvelopeEvent.java

@Test(groups = "fast")
public void testExternalization() throws Exception {
    final SmileEnvelopeEvent envelope = createEvent();

    final byte[] inputBytes = serializedBytes;
    final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(bytes);
    out.writeObject(envelope);//  w  w  w  .  j a va 2 s  . c  o  m
    out.close();
    final byte[] data = bytes.toByteArray();
    final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
    final Object ob = in.readObject();

    Assert.assertNotNull(ob);
    Assert.assertSame(SmileEnvelopeEvent.class, ob.getClass());

    final Event result = (SmileEnvelopeEvent) ob;
    // name is not automatically set, but can check other metadata
    Assert.assertSame(result.getGranularity(), eventGranularity);
    Assert.assertEquals(result.getEventDateTime(), eventDateTime);

    Assert.assertNotNull(result.getData());
    // TODO Looks like there are multiple JsonNode classes?
    //Assert.assertSame(result.getData().getClass(), JsonNode.class);
    Assert.assertEquals(result.getSerializedEvent(), inputBytes);
}

From source file:com.timesoft.kaitoo.ws.hibernate.AbstractPojo.java

/**
 * DOCUMENT ME!//from   ww  w . ja v  a  2s  . c  o m
 *
 * @return DOCUMENT ME!
 *
 * @throws Exception DOCUMENT ME!
 */
public byte[] serialize() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);

    try {
        oos.writeObject(this);
    } finally {
        oos.close();
    }

    return baos.toByteArray();
}

From source file:hydrograph.ui.graph.handler.JobCreationPage.java

protected InputStream getInitialContents() {
    ByteArrayInputStream bais = null;
    try {//from www .  j  a  v  a 2s .c om
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.flush();
        oos.close();
        bais = new ByteArrayInputStream(baos.toByteArray());
    } catch (IOException e) {
        logger.error("Error while job wizard creation", e);
    }
    return bais;
}

From source file:com.bskyb.cg.environments.hash.PersistentHash.java

private synchronized void appendEntryToStore(Message message) throws IOException {

    String filename = message.getKey();

    File file = new File(dirname, filename);
    FileOutputStream fos = new FileOutputStream(file, true);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    ObjectOutputStream oos = new ObjectOutputStream(bos);

    oos.writeObject(message);/*ww w .j  a v  a2s . co  m*/
    oos.flush();
    oos.close();
    fos.flush();
    fos.close();
}

From source file:com.izforge.izpack.event.BSFUninstallerListenerTest.java

/**
 * Creates a {@link BSFUninstallerListener} that uses the supplied actions.
 *
 * @param actions the actions/*from  w ww  . ja va2 s . co m*/
 * @return a new {@link BSFUninstallerListener}
 * @throws IOException for any I/O error
 */
private BSFUninstallerListener createListener(List<BSFAction> actions) throws IOException {
    // stream the actions, so the BSFUninstallerListener can read them as a resource
    assertNotNull(actions);
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream objectOutput = new ObjectOutputStream(byteOutput);
    objectOutput.writeObject(actions);
    objectOutput.close();

    Resources resources = Mockito.mock(Resources.class);
    ByteArrayInputStream byteInput = new ByteArrayInputStream(byteOutput.toByteArray());
    Mockito.when(resources.getInputStream("bsfActions")).thenReturn(byteInput);
    return new BSFUninstallerListener(resources);
}

From source file:cs.register.abrirefeichar.java

@Override
public void salvaresair(int status) {
    ObjectOutputStream objectOut = null;
    try {//from  w w  w. j a v  a2s.  c o  m
        objectOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("save")));
        objectOut.writeObject(this.list1);

        objectOut.close();
    } catch (IOException ex) {
        Logger.getLogger(abrirefeichar.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            objectOut.close();
        } catch (IOException ex) {
            Logger.getLogger(abrirefeichar.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (status == 0)
        System.exit(0);
}

From source file:cs.register.cddao.java

@Override
public void salvaresair(int status) {
    ObjectOutputStream objectOut = null;
    try {/*from  w  w w. ja  v a 2  s.com*/
        objectOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("save")));
        objectOut.writeObject(this.list1);

        objectOut.close();
    } catch (IOException ex) {
        Logger.getLogger(cddao.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            objectOut.close();
        } catch (IOException ex) {
            Logger.getLogger(cddao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (status == 0)
        System.exit(0);
}

From source file:io.lqd.sdk.model.LQLiquidPackage.java

public void saveToDisk(Context context) {
    LQLog.data("Saving to local storage");
    try {//from   ww w .  ja  v a 2  s .  c  o m
        FileOutputStream fileOutputStream = context.openFileOutput(LIQUID_PACKAGE_FILENAME + ".vars",
                Context.MODE_PRIVATE);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        objectOutputStream.writeObject(this);
        objectOutputStream.flush();
        objectOutputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
        LQLog.infoVerbose("Could not save liquid package to file");
    }
}