List of usage examples for java.io ObjectOutput close
public void close() throws IOException;
From source file:org.jfree.data.xy.junit.VectorSeriesCollectionTest.java
/** * Serialize an instance, restore it, and check for equality. */// ww w .j av a 2 s .co m 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. */// ww w .j a va2s .co m 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.chart.demo.ChartPanelSerializationTest.java
/** * A demonstration application showing how to create a simple time series chart. This * example uses monthly data.//w w w .j a va 2s . co m * * @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.DefaultHighLowDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from ww w .java2 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:com.ning.metrics.serialization.event.TestSmileEnvelopeEvent.java
@SuppressWarnings("deprecation") @Test(groups = "fast") public void testReadWriteExternal() throws Exception { final SmileEnvelopeEvent event = createEvent(); final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); final ObjectOutput out = new ObjectOutputStream(outStream); event.writeExternal(out);//from w w w . j av a2 s . c o m out.close(); final SmileEnvelopeEvent event2 = new SmileEnvelopeEvent(); event2.readExternal(new ObjectInputStream(new ByteArrayInputStream(outStream.toByteArray()))); Assert.assertEquals(event2.getName(), event.getName()); Assert.assertEquals(event2.getGranularity(), event.getGranularity()); Assert.assertEquals(event2.getName(), event.getName()); }
From source file:org.jfree.data.xy.junit.XIntervalSeriesCollectionTest.java
/** * Serialize an instance, restore it, and check for equality. *///from w w w .j av a 2 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 w ww . java 2 s . co m 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.conwet.silbops.model.SubscriptionTest.java
@Test public void shouldExternalize() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput output = new ObjectOutputStream(baos); output.writeObject(subscription);/*w ww .jav a 2 s. c o m*/ output.close(); ObjectInput input = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); assertThat((Subscription) input.readObject()).isEqualTo(subscription); }
From source file:com.conwet.silbops.model.AbstractMappingTest.java
@Test public void shouldExternalize() throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput output = new ObjectOutputStream(baos); output.writeObject(instance);//from w w w . j a v a2 s .c o m output.close(); ObjectInput input = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); T decoded = instance.getThisType().cast(input.readObject()); assertThat(decoded).isEqualTo(instance); }
From source file:org.jfree.data.xy.junit.XYIntervalSeriesCollectionTest.java
/** * Serialize an instance, restore it, and check for equality. *//* w w w . j av a2 s. c o m*/ public void testSerialization() { XYIntervalSeriesCollection c1 = new XYIntervalSeriesCollection(); XYIntervalSeries s1 = new XYIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3, 1.4, 1.5); XYIntervalSeriesCollection 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 = (XYIntervalSeriesCollection) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2); // check independence c1.addSeries(new XYIntervalSeries("Empty")); assertFalse(c1.equals(c2)); c2.addSeries(new XYIntervalSeries("Empty")); assertTrue(c1.equals(c2)); }