Example usage for java.io ObjectOutput close

List of usage examples for java.io ObjectOutput close

Introduction

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

Prototype

public void close() throws IOException;

Source Link

Document

Closes the stream.

Usage

From source file:com.conwet.silbops.msg.UnadvertiseMsgTest.java

@Test
public void shouldExternalize() throws Exception {
    UnadvertiseMsg unAdvMsg = new UnadvertiseMsg();

    Advertise subscription = new Advertise().attribute("attr1", Type.DOUBLE).attribute("attr2", Type.LONG)
            .attribute("attr3", Type.STRING);
    unAdvMsg.setAdvertise(subscription);

    Advertise uncovered1 = new Advertise().attribute("attr1", Type.DOUBLE).attribute("attr2", Type.LONG)
            .attribute("attr3", Type.STRING).attribute("attr4", Type.DOUBLE);

    Advertise uncovered2 = new Advertise().attribute("attr1", Type.DOUBLE).attribute("attr2", Type.LONG)
            .attribute("attr3", Type.STRING).attribute("attr5", Type.LONG);

    Set<Advertise> uncovered = new HashSet<>();
    uncovered.add(uncovered1);/*ww  w  .  ja  v a2s.co  m*/
    uncovered.add(uncovered2);
    unAdvMsg.setUncovered(uncovered);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutput output = new ObjectOutputStream(baos);

    output.writeObject(unAdvMsg);
    output.close();

    ObjectInput input = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));

    assertThat((UnadvertiseMsg) input.readObject()).isEqualTo(unAdvMsg);
}

From source file:com.conwet.silbops.msg.UnsubscribeMsgTest.java

@Test
public void shouldExternalizeAndDesexternalize() throws Exception {
    UnsubscribeMsg unSubMsg = new UnsubscribeMsg();

    Subscription subscription = new Subscription().constrain("attr1", Type.DOUBLE).ge(20.5D)
            .constrain("attr2", Type.LONG).eq(2L).constrain("attr3", Type.STRING).contains("TEST")
            .subscription();//from w  w  w .  ja  v a2s  . c  om
    unSubMsg.setSubscription(subscription);

    Subscription uncovered1 = new Subscription().constrain("attr1", Type.DOUBLE).ge(20.5D)
            .constrain("attr2", Type.LONG).eq(2L).constrain("attr3", Type.STRING).contains("TEST")
            .constrain("attr4", Type.DOUBLE).le(7D).subscription();

    Subscription uncovered2 = new Subscription().constrain("attr1", Type.DOUBLE).ge(20.5D)
            .constrain("attr2", Type.LONG).eq(2L).constrain("attr3", Type.STRING).contains("TEST")
            .constrain("attr4", Type.LONG).gt(7L).subscription();

    Set<Subscription> uncovered = new HashSet<>();
    uncovered.add(uncovered1);
    uncovered.add(uncovered2);
    unSubMsg.setUncovered(uncovered);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutput output = new ObjectOutputStream(baos);

    output.writeObject(unSubMsg);
    output.close();

    ObjectInput input = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));

    assertThat((UnsubscribeMsg) input.readObject()).isEqualTo(unSubMsg);
}

From source file:org.appverse.web.framework.backend.core.enterprise.aop.managers.impl.live.ProfileManagerImpl.java

private String getObjectSize(Object object) throws IOException {
    if (object instanceof Serializable) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(object);//from ww  w  .ja v  a  2s . c o  m
        out.close();

        byte[] buf = bos.toByteArray();
        return String.valueOf(buf.length);
    }
    return "Unknow";
}

From source file:MemComboBoxDemo.java

public void save(String fName) {
    try {//from   w w  w. ja v a2 s .  c  o  m
        FileOutputStream fStream = new FileOutputStream(fName);
        ObjectOutput stream = new ObjectOutputStream(fStream);

        stream.writeObject(getModel());

        stream.flush();
        stream.close();
        fStream.close();
    } catch (Exception e) {
        System.err.println("Serialization error: " + e.toString());
    }
}

From source file:org.jfree.chart.demo.SerializationTest1.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./*from  w  ww.j a v  a  2s.  co m*/
 */
public SerializationTest1(final String title) {

    super(title);
    this.series = new TimeSeries("Random Data", Millisecond.class);
    TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
    JFreeChart chart = createChart(dataset);

    // SERIALIZE - DESERIALIZE for testing purposes
    JFreeChart deserializedChart = null;

    try {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        final ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(chart);
        out.close();
        chart = null;
        dataset = null;
        this.series = null;
        System.gc();

        final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        deserializedChart = (JFreeChart) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    final TimeSeriesCollection c = (TimeSeriesCollection) deserializedChart.getXYPlot().getDataset();
    this.series = c.getSeries(0);
    // FINISHED TEST

    final ChartPanel chartPanel = new ChartPanel(deserializedChart);
    final JButton button = new JButton("Add New Data Item");
    button.setActionCommand("ADD_DATA");
    button.addActionListener(this);

    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    content.add(button, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

From source file:org.jfree.experimental.chart.annotations.junit.XYTitleAnnotationTests.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from  w ww  . jav a 2 s  .  co  m*/
public void testSerialization() {
    TextTitle t = new TextTitle("Title");
    XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t);
    XYTitleAnnotation a2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(a1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        a2 = (XYTitleAnnotation) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(a1, a2);
}

From source file:com.conwet.silbops.model.AdvertiseTest.java

@Test
public void shouldExternalize() throws Exception {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutput output = new ObjectOutputStream(baos);

    output.writeObject(advertise);/*from   w w  w.j a  v a2  s.  com*/
    output.close();

    ObjectInput input = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));

    assertThat((Advertise) input.readObject()).isEqualTo(advertise);
}

From source file:org.jfree.data.xy.junit.MatrixSeriesCollectionTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 */// w  ww .  java  2 s  .com
public void testSerialization() {
    MatrixSeries s1 = new MatrixSeries("Series", 2, 3);
    s1.update(0, 0, 1.1);
    MatrixSeriesCollection c1 = new MatrixSeriesCollection();
    c1.addSeries(s1);
    MatrixSeriesCollection c2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(c1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        c2 = (MatrixSeriesCollection) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}

From source file:com.ps.cc.controller.Init.java

@ActionMapping(params = "action=saveTwilioConfiguration")
public void saveTwilioConfiguration(@ModelAttribute TwilioConfiguration twilioConfiguration,
        ActionRequest actionRequest) throws Exception {
    ObjectOutput out = new ObjectOutputStream(new FileOutputStream("twilioConfiguration.txt"));
    out.writeObject(twilioConfiguration);
    out.close();

    User user = PortalUtil.getUser(actionRequest);

    TwilioCapability capability = new TwilioCapability(twilioConfiguration.getAcctSid(),
            twilioConfiguration.getAuthToken());

    capability.allowEventStream(null);/*from w ww. j  a v a 2 s. com*/
    capability.allowClientIncoming(user.getScreenName());

    Map<String, String> params = new HashMap<String, String>();
    params.put("portraitId", String.valueOf(user.getPortraitId()));

    capability.allowClientOutgoing(twilioConfiguration.getAppSid(), params);

    String token = capability.generateToken();

    PortalUtil.getHttpServletRequest(actionRequest).getSession().setAttribute("USER_twilio_token", token);
}

From source file:org.jfree.data.xy.junit.XYBarDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from  w ww . j  av a  2  s .  c  om
public void testSerialization() {
    DefaultXYDataset d1 = new DefaultXYDataset();
    double[] x1 = new double[] { 1.0, 2.0, 3.0 };
    double[] y1 = new double[] { 4.0, 5.0, 6.0 };
    double[][] data1 = new double[][] { x1, y1 };
    d1.addSeries("S1", data1);
    XYBarDataset bd1 = new XYBarDataset(d1, 5.0);
    XYBarDataset bd2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(bd1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        bd2 = (XYBarDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(bd1, bd2);
}