Showing the changes to java/pkg/javax/management/loading/MLetObjectInputStream.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,122 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 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 | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package javax.management.loading; | ||
| 27 | |||
| 28 | |||
| 29 | // java import | ||
| 30 | |||
| 31 | import java.io.*; | ||
| 32 | import java.lang.reflect.Array; | ||
| 33 | |||
| 34 | |||
| 35 | /** | ||
| 36 | * This subclass of ObjectInputStream delegates loading of classes to | ||
| 37 | * an existing MLetClassLoader. | ||
| 38 | * | ||
| 39 | * @since 1.5 | ||
| 40 | */ | ||
| 41 | class MLetObjectInputStream extends ObjectInputStream { | ||
| 42 | |||
| 43 | private MLet loader; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Loader must be non-null; | ||
| 47 | */ | ||
| 48 | public MLetObjectInputStream(InputStream in, MLet loader) | ||
| 49 | throws IOException, StreamCorruptedException { | ||
| 50 | |||
| 51 | super(in); | ||
| 52 | if (loader == null) { | ||
| 53 | throw new IllegalArgumentException("Illegal null argument to MLetObjectInputStream"); | ||
| 54 | } | ||
| 55 | this.loader = loader; | ||
| 56 | } | ||
| 57 | |||
| 58 | private Class<?> primitiveType(char c) { | ||
| 59 | switch(c) { | ||
| 60 | case 'B': | ||
| 61 | return Byte.TYPE; | ||
| 62 | |||
| 63 | case 'C': | ||
| 64 | return Character.TYPE; | ||
| 65 | |||
| 66 | case 'D': | ||
| 67 | return Double.TYPE; | ||
| 68 | |||
| 69 | case 'F': | ||
| 70 | return Float.TYPE; | ||
| 71 | |||
| 72 | case 'I': | ||
| 73 | return Integer.TYPE; | ||
| 74 | |||
| 75 | case 'J': | ||
| 76 | return Long.TYPE; | ||
| 77 | |||
| 78 | case 'S': | ||
| 79 | return Short.TYPE; | ||
| 80 | |||
| 81 | case 'Z': | ||
| 82 | return Boolean.TYPE; | ||
| 83 | } | ||
| 84 | return null; | ||
| 85 | } | ||
| 86 | |||
| 87 | /** | ||
| 88 | * Use the given ClassLoader rather than using the system class | ||
| 89 | */ | ||
| 90 | @Override | ||
| 91 | protected Class<?> resolveClass(ObjectStreamClass objectstreamclass) | ||
| 92 | throws IOException, ClassNotFoundException { | ||
| 93 | |||
| 94 | String s = objectstreamclass.getName(); | ||
| 95 | if (s.startsWith("[")) { | ||
| 96 | int i; | ||
| 97 | for (i = 1; s.charAt(i) == '['; i++); | ||
| 98 | Class<?> class1; | ||
| 99 | if (s.charAt(i) == 'L') { | ||
| 100 | class1 = loader.loadClass(s.substring(i + 1, s.length() - 1)); | ||
| 101 | } else { | ||
| 102 | if (s.length() != i + 1) | ||
| 103 | throw new ClassNotFoundException(s); | ||
| 104 | class1 = primitiveType(s.charAt(i)); | ||
| 105 | } | ||
| 106 | int ai[] = new int[i]; | ||
| 107 | for (int j = 0; j < i; j++) | ||
| 108 | ai[j] = 0; | ||
| 109 | |||
| 110 | return Array.newInstance(class1, ai).getClass(); | ||
| 111 | } else { | ||
| 112 | return loader.loadClass(s); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * Returns the ClassLoader being used | ||
| 118 | */ | ||
| 119 | public ClassLoader getClassLoader() { | ||
| 120 | return loader; | ||
| 121 | } | ||
| 122 | } | ||