Code example for ObjectOutputStream

Methods: close, writeObject

0
  private byte[] serializeReportObject(final MasterReport report) throws IOException
  { 
    // we don't test whether our demo models are serializable :) 
    // clear all report properties, which may cause trouble ... 
    final MemoryByteArrayOutputStream bo = new MemoryByteArrayOutputStream();
    final ObjectOutputStream oout = new ObjectOutputStream(bo);
    oout.writeObject(report);
    oout.close();
    return bo.toByteArray();
  } 
 
  private MasterReport deserializeReportObject(final byte[] data) throws IOException, ClassNotFoundException
  { 
    final ByteArrayInputStream bin = new ByteArrayInputStream(data);
    final ObjectInputStream oin = new ObjectInputStream(bin);
    final MasterReport report2 = (MasterReport) oin.readObject();
    assertNotNull(report2);
    return report2;
  } 
 
  @Test