Code example for ObjectOutputStream

Methods: close, flush, writeByte

0
 
	public void test_4_flush() { 
		// Test for method void java.io.ObjectOutputStream.flush() 
		try { 
			oos.close();
			oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
			int size = bao.size();
			oos.writeByte(127);
			assertTrue("Data flushed already", bao.size() == size);
			oos.flush();
			assertTrue("Failed to flush data", bao.size() > size);
			// we don't know how many bytes are actually written for 1 byte, 
			// so we test > <before> 
			oos.close();
			oos = null;
		} catch (IOException e) {
			fail("IOException serializing data : " + e.getMessage());
		} 
	} 
 
	public void test_5_reset() {