jdk/src/java.desktop/share/classes/sun/applet/AppletObjectInputStream.java
author serb
Thu, 22 Dec 2016 18:09:58 +0300
changeset 43078 1d242b27f9e2
parent 25859 3317bb8137f4
permissions -rw-r--r--
8169900: The code which use Applets should be deprecated Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 1997, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * COPYRIGHT goes here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package sun.applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This subclass of ObjectInputStream delegates loading of classes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * an existing ClassLoader.
43078
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 25859
diff changeset
    37
 *
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 25859
diff changeset
    38
 * @deprecated The Applet API is deprecated. See the
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 25859
diff changeset
    39
 * <a href="../../java/applet/package-summary.html"> java.applet package
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 25859
diff changeset
    40
 * documentation</a> for further information.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
43078
1d242b27f9e2 8169900: The code which use Applets should be deprecated
serb
parents: 25859
diff changeset
    42
@Deprecated(since = "9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class AppletObjectInputStream extends ObjectInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private AppletClassLoader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Loader must be non-null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public AppletObjectInputStream(InputStream in, AppletClassLoader loader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            throws IOException, StreamCorruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (loader == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            throw new AppletIllegalArgumentException("appletillegalargumentexception.objectinputstream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.loader = loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Make a primitive array class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 5506
diff changeset
    66
    private Class<?> primitiveType(char type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        case 'B': return byte.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        case 'C': return char.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        case 'D': return double.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        case 'F': return float.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        case 'I': return int.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        case 'J': return long.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        case 'S': return short.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        case 'Z': return boolean.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        default: return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Use the given ClassLoader rather than using the system class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 5506
diff changeset
    83
    protected Class<?> resolveClass(ObjectStreamClass classDesc)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        String cname = classDesc.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (cname.startsWith("[")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            // An array
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 5506
diff changeset
    89
            Class<?> component;            // component class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            int dcount;                 // dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            for (dcount=1; cname.charAt(dcount)=='['; dcount++) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (cname.charAt(dcount) == 'L') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                component = loader.loadClass(cname.substring(dcount+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                                             cname.length()-1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                if (cname.length() != dcount+1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    throw new ClassNotFoundException(cname);// malformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                component = primitiveType(cname.charAt(dcount));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            int dim[] = new int[dcount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            for (int i=0; i<dcount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                dim[i]=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return Array.newInstance(component, dim).getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return loader.loadClass(cname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}