Developing Java Beans private void readObject(ObjectInputStream stream) throws

Developing Java Beans private void readObject(ObjectInputStream stream) throws java.io.IOException { System.out.println(”readObject called for class C”); try { stream.defaultReadObject(); } catch (ClassNotFoundException e) { throw new IOException(); } } public C() { super(); } } We can write a simple test to illustrate the order in which the class hierarchy is serialized. Let’s create an application that creates an instance of class C, writes it to an instance of java.io.ObjectOutputStream, and then reads it back from an instance of java.io.ObjectInputStream. Note that we use ByteArray streams since we have no need to store anything to disk. The code for the application looks like this: import java.io.*; public class Example7 { // the application entry pointpublic static void main(String[] args) { // the byte array buffer byte[] buffer = null; // create an instance of class C C c = new C(); try { ByteArrayOutputStream f = new ByteArrayOutputStream(); ObjectOutputStream s = new ObjectOutputStream(f); s.writeObject(c); s.flush(); buffer = f.toByteArray(); } catch (Exception e) { System.out.println(e); } try { ByteArrayInputStream f = new ByteArrayInputStream(buffer); ObjectInputStream s = new ObjectInputStream(f); c = (C)s.readObject(); } catch (Exception e) { System.out.println(e); } page 81
Note: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting services

Comments are closed.