Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/applet/AppletObjectInputStream.java
38829 views
/*1* Copyright (c) 1996, 1997, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24/*25* COPYRIGHT goes here26*/2728package sun.applet;2930import java.io.*;31import java.lang.reflect.Array;3233/**34* This subclass of ObjectInputStream delegates loading of classes to35* an existing ClassLoader.36*/3738class AppletObjectInputStream extends ObjectInputStream39{40private AppletClassLoader loader;4142/**43* Loader must be non-null;44*/4546public AppletObjectInputStream(InputStream in, AppletClassLoader loader)47throws IOException, StreamCorruptedException {4849super(in);50if (loader == null) {51throw new AppletIllegalArgumentException("appletillegalargumentexception.objectinputstream");5253}54this.loader = loader;55}5657/**58* Make a primitive array class59*/6061private Class primitiveType(char type) {62switch (type) {63case 'B': return byte.class;64case 'C': return char.class;65case 'D': return double.class;66case 'F': return float.class;67case 'I': return int.class;68case 'J': return long.class;69case 'S': return short.class;70case 'Z': return boolean.class;71default: return null;72}73}7475/**76* Use the given ClassLoader rather than using the system class77*/78protected Class resolveClass(ObjectStreamClass classDesc)79throws IOException, ClassNotFoundException {8081String cname = classDesc.getName();82if (cname.startsWith("[")) {83// An array84Class component; // component class85int dcount; // dimension86for (dcount=1; cname.charAt(dcount)=='['; dcount++) ;87if (cname.charAt(dcount) == 'L') {88component = loader.loadClass(cname.substring(dcount+1,89cname.length()-1));90} else {91if (cname.length() != dcount+1) {92throw new ClassNotFoundException(cname);// malformed93}94component = primitiveType(cname.charAt(dcount));95}96int dim[] = new int[dcount];97for (int i=0; i<dcount; i++) {98dim[i]=0;99}100return Array.newInstance(component, dim).getClass();101} else {102return loader.loadClass(cname);103}104}105}106107108