42
43 /**
44 * Loader must be non-null;
45 */
46
47 public AppletObjectInputStream(InputStream in, AppletClassLoader loader)
48 throws IOException, StreamCorruptedException {
49
50 super(in);
51 if (loader == null) {
52 throw new AppletIllegalArgumentException("appletillegalargumentexception.objectinputstream");
53
54 }
55 this.loader = loader;
56 }
57
58 /**
59 * Make a primitive array class
60 */
61
62 private Class primitiveType(char type) {
63 switch (type) {
64 case 'B': return byte.class;
65 case 'C': return char.class;
66 case 'D': return double.class;
67 case 'F': return float.class;
68 case 'I': return int.class;
69 case 'J': return long.class;
70 case 'S': return short.class;
71 case 'Z': return boolean.class;
72 default: return null;
73 }
74 }
75
76 /**
77 * Use the given ClassLoader rather than using the system class
78 */
79 protected Class resolveClass(ObjectStreamClass classDesc)
80 throws IOException, ClassNotFoundException {
81
82 String cname = classDesc.getName();
83 if (cname.startsWith("[")) {
84 // An array
85 Class component; // component class
86 int dcount; // dimension
87 for (dcount=1; cname.charAt(dcount)=='['; dcount++) ;
88 if (cname.charAt(dcount) == 'L') {
89 component = loader.loadClass(cname.substring(dcount+1,
90 cname.length()-1));
91 } else {
92 if (cname.length() != dcount+1) {
93 throw new ClassNotFoundException(cname);// malformed
94 }
95 component = primitiveType(cname.charAt(dcount));
96 }
97 int dim[] = new int[dcount];
98 for (int i=0; i<dcount; i++) {
99 dim[i]=0;
100 }
101 return Array.newInstance(component, dim).getClass();
102 } else {
103 return loader.loadClass(cname);
104 }
105 }
|
42
43 /**
44 * Loader must be non-null;
45 */
46
47 public AppletObjectInputStream(InputStream in, AppletClassLoader loader)
48 throws IOException, StreamCorruptedException {
49
50 super(in);
51 if (loader == null) {
52 throw new AppletIllegalArgumentException("appletillegalargumentexception.objectinputstream");
53
54 }
55 this.loader = loader;
56 }
57
58 /**
59 * Make a primitive array class
60 */
61
62 private Class<?> primitiveType(char type) {
63 switch (type) {
64 case 'B': return byte.class;
65 case 'C': return char.class;
66 case 'D': return double.class;
67 case 'F': return float.class;
68 case 'I': return int.class;
69 case 'J': return long.class;
70 case 'S': return short.class;
71 case 'Z': return boolean.class;
72 default: return null;
73 }
74 }
75
76 /**
77 * Use the given ClassLoader rather than using the system class
78 */
79 protected Class<?> resolveClass(ObjectStreamClass classDesc)
80 throws IOException, ClassNotFoundException {
81
82 String cname = classDesc.getName();
83 if (cname.startsWith("[")) {
84 // An array
85 Class<?> component; // component class
86 int dcount; // dimension
87 for (dcount=1; cname.charAt(dcount)=='['; dcount++) ;
88 if (cname.charAt(dcount) == 'L') {
89 component = loader.loadClass(cname.substring(dcount+1,
90 cname.length()-1));
91 } else {
92 if (cname.length() != dcount+1) {
93 throw new ClassNotFoundException(cname);// malformed
94 }
95 component = primitiveType(cname.charAt(dcount));
96 }
97 int dim[] = new int[dcount];
98 for (int i=0; i<dcount; i++) {
99 dim[i]=0;
100 }
101 return Array.newInstance(component, dim).getClass();
102 } else {
103 return loader.loadClass(cname);
104 }
105 }
|