1098 byte[] tb = new byte[len];
1099 b.get(tb); // get bytes out of byte buffer.
1100 return defineClass(name, tb, 0, len, protectionDomain);
1101 }
1102 }
1103
1104 protectionDomain = preDefineClass(name, protectionDomain);
1105 String source = defineClassSourceLocation(protectionDomain);
1106 Class<?> c = defineClass2(this, name, b, b.position(), len, protectionDomain, source);
1107 postDefineClass(c, protectionDomain);
1108 return c;
1109 }
1110
1111 static native Class<?> defineClass1(ClassLoader loader, String name, byte[] b, int off, int len,
1112 ProtectionDomain pd, String source);
1113
1114 static native Class<?> defineClass2(ClassLoader loader, String name, java.nio.ByteBuffer b,
1115 int off, int len, ProtectionDomain pd,
1116 String source);
1117
1118 // true if the name is null or has the potential to be a valid binary name
1119 private boolean checkName(String name) {
1120 if ((name == null) || (name.isEmpty()))
1121 return true;
1122 if ((name.indexOf('/') != -1) || (name.charAt(0) == '['))
1123 return false;
1124 return true;
1125 }
1126
1127 private void checkCerts(String name, CodeSource cs) {
1128 int i = name.lastIndexOf('.');
1129 String pname = (i == -1) ? "" : name.substring(0, i);
1130
1131 Certificate[] certs = null;
1132 if (cs != null) {
1133 certs = cs.getCertificates();
1134 }
1135 certs = certs == null ? nocerts : certs;
1136 Certificate[] pcerts = package2certs.putIfAbsent(pname, certs);
1137 if (pcerts != null && !compareCerts(pcerts, certs)) {
|
1098 byte[] tb = new byte[len];
1099 b.get(tb); // get bytes out of byte buffer.
1100 return defineClass(name, tb, 0, len, protectionDomain);
1101 }
1102 }
1103
1104 protectionDomain = preDefineClass(name, protectionDomain);
1105 String source = defineClassSourceLocation(protectionDomain);
1106 Class<?> c = defineClass2(this, name, b, b.position(), len, protectionDomain, source);
1107 postDefineClass(c, protectionDomain);
1108 return c;
1109 }
1110
1111 static native Class<?> defineClass1(ClassLoader loader, String name, byte[] b, int off, int len,
1112 ProtectionDomain pd, String source);
1113
1114 static native Class<?> defineClass2(ClassLoader loader, String name, java.nio.ByteBuffer b,
1115 int off, int len, ProtectionDomain pd,
1116 String source);
1117
1118 /**
1119 * Defines a class of the given flags via Lookup.defineClass.
1120 *
1121 * @param loader the defining loader
1122 * @param lookup nest host of the Class to be defined
1123 * @param name the binary name or {@code null} if not findable
1124 * @param b class bytes
1125 * @param off the start offset in {@code b} of the class bytes
1126 * @param len the length of the class bytes
1127 * @param pd protection domain
1128 * @param initialize initialize the class
1129 * @param flags flags
1130 * @param classData class data
1131 */
1132 static native Class<?> defineClass0(ClassLoader loader,
1133 Class<?> lookup,
1134 String name,
1135 byte[] b, int off, int len,
1136 ProtectionDomain pd,
1137 boolean initialize,
1138 int flags,
1139 Object classData);
1140
1141 // true if the name is null or has the potential to be a valid binary name
1142 private boolean checkName(String name) {
1143 if ((name == null) || (name.isEmpty()))
1144 return true;
1145 if ((name.indexOf('/') != -1) || (name.charAt(0) == '['))
1146 return false;
1147 return true;
1148 }
1149
1150 private void checkCerts(String name, CodeSource cs) {
1151 int i = name.lastIndexOf('.');
1152 String pname = (i == -1) ? "" : name.substring(0, i);
1153
1154 Certificate[] certs = null;
1155 if (cs != null) {
1156 certs = cs.getCertificates();
1157 }
1158 certs = certs == null ? nocerts : certs;
1159 Certificate[] pcerts = package2certs.putIfAbsent(pname, certs);
1160 if (pcerts != null && !compareCerts(pcerts, certs)) {
|