List of usage examples for java.io ObjectOutput close
public void close() throws IOException;
From source file:com.sherdle.universal.ConfigParser.java
public void saveJSONToCache(String json) { // Instantiate a JSON object from the request response try {/*from w w w . j a va 2 s . c o m*/ // Save the JSONObject ObjectOutput out = null; out = new ObjectOutputStream(new FileOutputStream(new File(context.getCacheDir(), "") + CACHE_FILE)); out.writeObject(json); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.jfree.data.time.junit.MillisecondTest.java
/** * Serialize an instance, restore it, and check for equality. *///from www . ja va 2 s . c om public void testSerialization() { Millisecond m1 = new Millisecond(); Millisecond m2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); m2 = (Millisecond) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(m1, m2); }
From source file:org.jfree.data.time.junit.HourTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from ww w .j a va2 s . c o m*/ public void testSerialization() { Hour h1 = new Hour(); Hour h2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(h1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); h2 = (Hour) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(h1, h2); }
From source file:org.jfree.data.category.junit.DefaultCategoryDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *//*w ww. j a va 2 s.c om*/ public void testSerialization() { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); d1.setValue(23.4, "R1", "C1"); DefaultCategoryDataset 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 = (DefaultCategoryDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); }
From source file:org.jfree.data.xy.junit.DefaultIntervalXYDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *///from www. jav a2 s.c o m public void testSerialization() { DefaultIntervalXYDataset d1 = new DefaultIntervalXYDataset(); DefaultIntervalXYDataset 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 = (DefaultIntervalXYDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); // try a dataset with some content... d1 = createSampleDataset1(); try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); d2 = (DefaultIntervalXYDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); }
From source file:org.jfree.data.time.junit.DayTest.java
/** * Serialize an instance, restore it, and check for equality. *///from w w w .j a v a2 s . c o m public void testSerialization() { Day d1 = new Day(15, 4, 2000); Day 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 = (Day) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); }
From source file:com.hp.saas.agm.rest.client.SessionContext.java
public void save(File targetFile) { ObjectOutput out = null; try {/* w ww. ja va 2 s . c o m*/ out = new ObjectOutputStream(new FileOutputStream(targetFile)); out.writeObject(this); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { logger.log(Level.SEVERE, "IOException thrown while closing stream.", e); } } } }
From source file:org.jfree.data.time.junit.TimePeriodValuesTest.java
/** * Serialize an instance, restore it, and check for equality. *///from w w w . j a v a2 s.c om public void testSerialization() { TimePeriodValues s1 = new TimePeriodValues("A test"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); TimePeriodValues s2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); s2 = (TimePeriodValues) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertTrue(s1.equals(s2)); }
From source file:org.jfree.data.time.junit.MonthTest.java
/** * Serialize an instance, restore it, and check for equality. *//*w w w. j a va 2 s .com*/ public void testSerialization() { Month m1 = new Month(12, 1999); Month m2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); m2 = (Month) in.readObject(); in.close(); } catch (Exception e) { System.out.println(e.toString()); } assertEquals(m1, m2); }
From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java
/** * Serialize an instance, restore it, and check for equality. *///ww w. jav a2 s . c o m public void testSerialization() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeriesCollection 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 = (XYSeriesCollection) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2); }