test/jdk/java/io/Serializable/classDescHooks/Loopback.java
changeset 58565 baa5969ecf34
parent 47216 71c04702a3d5
equal deleted inserted replaced
58564:218a1a642c6f 58565:baa5969ecf34
     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.
    31 
    31 
    32 import java.io.*;
    32 import java.io.*;
    33 import java.util.*;
    33 import java.util.*;
    34 
    34 
    35 class LoopbackOutputStream extends ObjectOutputStream {
    35 class LoopbackOutputStream extends ObjectOutputStream {
    36     LinkedList descs;
    36     LinkedList<ObjectStreamClass> descs;
    37 
    37 
    38     LoopbackOutputStream(OutputStream out, LinkedList descs)
    38     LoopbackOutputStream(OutputStream out, LinkedList<ObjectStreamClass> descs)
    39         throws IOException
    39         throws IOException
    40     {
    40     {
    41         super(out);
    41         super(out);
    42         this.descs = descs;
    42         this.descs = descs;
    43     }
    43     }
    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