Code example for ObjectOutputStream

Methods: close, writeObject

0
      throws IOException, ClassNotFoundException 
  { 
    final CustomPageDefinition cpd = new CustomPageDefinition();
 
    final ByteArrayOutputStream bo = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(bo);
    out.writeObject(cpd);
    out.close();
 
    final ObjectInputStream oin = new ObjectInputStream
        (new ByteArrayInputStream(bo.toByteArray()));
    final Object e2 = oin.readObject();
    assertNotNull(e2); // cannot assert equals, as this is not implemented.
    assertEquals(cpd, e2);
  } 
 
  public void testSerializeFilled() 
      throws IOException, ClassNotFoundException 
  { 
    final CustomPageDefinition cpd = new CustomPageDefinition();
    cpd.addPageFormat(new PageFormat(), 0, 0);