Example usage for java.io ObjectInput readObject

List of usage examples for java.io ObjectInput readObject

Introduction

In this page you can find the example usage for java.io ObjectInput readObject.

Prototype

public Object readObject() throws ClassNotFoundException, IOException;

Source Link

Document

Read and return an object.

Usage

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

/**
 * A demonstration application showing how to create a simple time series chart.  This
 * example uses monthly data.//from ww w  .  j av  a  2 s  .  com
 *
 * @param title  the frame title.
 */
public ChartPanelSerializationTest(final String title) {

    super(title);
    final XYDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel1 = new ChartPanel(chart);
    chartPanel1.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel1.setMouseZoomable(true, false);

    ChartPanel chartPanel2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(chartPanel1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        chartPanel2 = (ChartPanel) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    setContentPane(chartPanel2);

}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *///  ww w .  ja  va  2  s. c om
public void testSerialization() {
    VectorSeries s1 = new VectorSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    VectorSeriesCollection c1 = new VectorSeriesCollection();
    c1.addSeries(s1);
    VectorSeriesCollection 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 = (VectorSeriesCollection) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*w w w. jav  a2 s . com*/
public void testSerialization() {
    DefaultOHLCDataset d1 = new DefaultOHLCDataset("Series 1", new OHLCDataItem[0]);
    DefaultOHLCDataset d2 = null;

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

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (DefaultOHLCDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(d1, d2);
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *///from   w w  w .ja  v  a2 s  .c  o m
public void testSerialization() {
    DefaultHighLowDataset d1 = new DefaultHighLowDataset("Series 1", new Date[] { new Date(123L) },
            new double[] { 1.2 }, new double[] { 3.4 }, new double[] { 5.6 }, new double[] { 7.8 },
            new double[] { 99.9 });
    DefaultHighLowDataset d2 = null;

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

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (DefaultHighLowDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);
}

From source file:xbird.xquery.expr.func.FunctionCall.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this._type = (Type) in.readObject();
    this._funcName = QualifiedName.readFrom(in);
    final int numParams = in.readInt();
    final ArrayList<XQExpression> params = new ArrayList<XQExpression>(numParams);
    for (int i = 0; i < numParams; i++) {
        XQExpression e = (XQExpression) in.readObject();
        params.add(e);/*from   ww w. j  a v  a2s  .  c  o  m*/
    }
    this._params = params;
}

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

@Test
public void shouldExternalize() throws Exception {

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

    output.writeObject(subscription);/*ww  w  .j  a  va 2 s  .co m*/
    output.close();

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

    assertThat((Subscription) input.readObject()).isEqualTo(subscription);
}

From source file:xbird.xquery.expr.opt.ShippedVariable.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this._local = false;
    this._type = (Type) in.readObject();
    this._varName = (QualifiedName) in.readObject();
    this._identifier = in.readInt();

    final boolean hasResult = in.readBoolean();
    if (hasResult) {
        final boolean isRemoteSeq = in.readBoolean();
        if (isRemoteSeq) {
            this._result = RemoteSequence.readFrom(in);
        } else {/*from w w w .  j av a2  s  .c o  m*/
            final StopWatch sw = new StopWatch("Elapsed time for decoding `$" + getName() + '\'');
            final XQEventDecoder decoder = new XQEventDecoder(in);
            try {
                this._result = decoder.decode();
            } catch (XQueryException xqe) {
                throw new IllegalStateException("failed decoding `$" + getName() + '\'', xqe);
            } catch (Throwable e) {
                throw new IllegalStateException("failed decoding `$" + getName() + '\'', e);
            }
            if (LOG.isInfoEnabled()) {
                LOG.info(sw);
            }
        }
    } else {
        this._value = (XQExpression) in.readObject();
    }
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *///from  ww  w.  j  a v  a2 s.c om
public void testSerialization() {
    XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
    XIntervalSeries s1 = new XIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    XIntervalSeriesCollection 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 = (XIntervalSeriesCollection) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *///from www.j  a  va  2s.c  om
public void testSerialization() {
    YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeriesCollection 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 = (YIntervalSeriesCollection) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}

From source file:com.splicemachine.derby.impl.sql.execute.operations.GroupedAggregateOperation.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);
    isRollup = in.readBoolean();/*from  w ww .jav a2s  . c o  m*/
    groupedAggregateContext = (GroupedAggregateContext) in.readObject();
}