(String[] args)
| 45 | return result.toString(); |
| 46 | } |
| 47 | public static void |
| 48 | main(String[] args) throws ClassNotFoundException, |
| 49 | IOException { |
| 50 | Worm w = new Worm(6, 'a'); |
| 51 | System.out.println("w = " + w); |
| 52 | try( |
| 53 | ObjectOutputStream out = new ObjectOutputStream( |
| 54 | new FileOutputStream("worm.dat")) |
| 55 | ) { |
| 56 | out.writeObject("Worm storage\n"); |
| 57 | out.writeObject(w); |
| 58 | } |
| 59 | try( |
| 60 | ObjectInputStream in = new ObjectInputStream( |
| 61 | new FileInputStream("worm.dat")) |
| 62 | ) { |
| 63 | String s = (String)in.readObject(); |
| 64 | Worm w2 = (Worm)in.readObject(); |
| 65 | System.out.println(s + "w2 = " + w2); |
| 66 | } |
| 67 | try( |
| 68 | ByteArrayOutputStream bout = |
| 69 | new ByteArrayOutputStream(); |
| 70 | ObjectOutputStream out2 = |
| 71 | new ObjectOutputStream(bout) |
| 72 | ) { |
| 73 | out2.writeObject("Worm storage\n"); |
| 74 | out2.writeObject(w); |
| 75 | out2.flush(); |
| 76 | try( |
| 77 | ObjectInputStream in2 = new ObjectInputStream( |
| 78 | new ByteArrayInputStream( |
| 79 | bout.toByteArray())) |
| 80 | ) { |
| 81 | String s = (String)in2.readObject(); |
| 82 | Worm w3 = (Worm)in2.readObject(); |
| 83 | System.out.println(s + "w3 = " + w3); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | /* Output: |
| 89 | Worm constructor: 6 |
nothing calls this directly
no test coverage detected