MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

serialization/Blips.java:41–68  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

39
40public class Blips {
41 public static void main(String[] args) {
42 System.out.println("Constructing objects:");
43 Blip1 b1 = new Blip1();
44 Blip2 b2 = new Blip2();
45 try(
46 ObjectOutputStream o = new ObjectOutputStream(
47 new FileOutputStream("Blips.serialized"))
48 ) {
49 System.out.println("Saving objects:");
50 o.writeObject(b1);
51 o.writeObject(b2);
52 } catch(IOException e) {
53 throw new RuntimeException(e);
54 }
55 // Now get them back:
56 System.out.println("Recovering b1:");
57 try(
58 ObjectInputStream in = new ObjectInputStream(
59 new FileInputStream("Blips.serialized"))
60 ) {
61 b1 = (Blip1)in.readObject();
62 } catch(IOException | ClassNotFoundException e) {
63 throw new RuntimeException(e);
64 }
65 // OOPS! Throws an exception:
66 //- System.out.println("Recovering b2:");
67 //- b2 = (Blip2)in.readObject();
68 }
69}
70/* Output:
71Constructing objects:

Callers

nothing calls this directly

Calls 2

writeObjectMethod · 0.80
readObjectMethod · 0.80

Tested by

no test coverage detected