1 /* |
1 /* |
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
48 descs.add(desc); |
48 descs.add(desc); |
49 } |
49 } |
50 } |
50 } |
51 |
51 |
52 class LoopbackInputStream extends ObjectInputStream { |
52 class LoopbackInputStream extends ObjectInputStream { |
53 LinkedList descs; |
53 LinkedList<ObjectStreamClass> descs; |
54 |
54 |
55 LoopbackInputStream(InputStream in, LinkedList descs) throws IOException { |
55 LoopbackInputStream(InputStream in, LinkedList<ObjectStreamClass> descs) throws IOException { |
56 super(in); |
56 super(in); |
57 this.descs = descs; |
57 this.descs = descs; |
58 } |
58 } |
59 |
59 |
60 protected ObjectStreamClass readClassDescriptor() |
60 protected ObjectStreamClass readClassDescriptor() |
61 throws IOException, ClassNotFoundException |
|
62 { |
61 { |
63 return (ObjectStreamClass) descs.removeFirst(); |
62 return descs.removeFirst(); |
64 } |
63 } |
65 } |
64 } |
66 |
65 |
67 public class Loopback implements Serializable { |
66 public class Loopback implements Serializable { |
|
67 private static final long serialVersionUID = 1L; |
|
68 |
68 String str; |
69 String str; |
69 |
70 |
70 Loopback(String str) { |
71 Loopback(String str) { |
71 this.str = str; |
72 this.str = str; |
72 } |
73 } |
73 |
74 |
74 public static void main(String[] args) throws Exception { |
75 public static void main(String[] args) throws Exception { |
75 Loopback lb = new Loopback("foo"); |
76 Loopback lb = new Loopback("foo"); |
76 LinkedList descs = new LinkedList(); |
77 LinkedList<ObjectStreamClass> descs = new LinkedList<>(); |
77 ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
78 ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
78 LoopbackOutputStream lout = new LoopbackOutputStream(bout, descs); |
79 LoopbackOutputStream lout = new LoopbackOutputStream(bout, descs); |
79 lout.writeObject(lb); |
80 lout.writeObject(lb); |
80 lout.close(); |
81 lout.close(); |
81 |
82 |