1141 private static class DefaultFactory implements URLStreamHandlerFactory {
1142 private static String PREFIX = "sun.net.www.protocol";
1143
1144 public URLStreamHandler createURLStreamHandler(String protocol) {
1145 String name = PREFIX + "." + protocol + ".Handler";
1146 try {
1147 Class<?> c = Class.forName(name);
1148 return (URLStreamHandler)c.newInstance();
1149 } catch (ClassNotFoundException x) {
1150 // ignore
1151 } catch (Exception e) {
1152 // For compatibility, all Exceptions are ignored.
1153 // any number of exceptions can get thrown here
1154 }
1155 return null;
1156 }
1157 }
1158
1159 private static URLStreamHandler lookupViaProperty(String protocol) {
1160 String packagePrefixList = java.security.AccessController.doPrivileged(
1161 new PrivilegedAction<String>() {
1162 public String run() {
1163 return System.getProperty(protocolPathProp, "");
1164 }
1165 });
1166 String[] packagePrefixes = packagePrefixList.split("\\|");
1167
1168 URLStreamHandler handler = null;
1169 for (int i=0; handler == null && i<packagePrefixes.length; i++) {
1170 String packagePrefix = packagePrefixes[i].trim();
1171 try {
1172 String clsName = packagePrefix + "." + protocol + ".Handler";
1173 Class<?> cls = null;
1174 try {
1175 cls = Class.forName(clsName);
1176 } catch (ClassNotFoundException e) {
1177 ClassLoader cl = ClassLoader.getSystemClassLoader();
1178 if (cl != null) {
1179 cls = cl.loadClass(clsName);
1180 }
1181 }
1182 if (cls != null) {
1183 handler = (URLStreamHandler)cls.newInstance();
1184 }
1185 } catch (Exception e) {
1186 // any number of exceptions can get thrown here
1187 }
1188 }
1189 return handler;
1190 }
1191
1192 private static Iterator<URLStreamHandlerProvider> providers() {
1193 return new Iterator<URLStreamHandlerProvider>() {
1194
1195 ClassLoader cl = ClassLoader.getSystemClassLoader();
1196 ServiceLoader<URLStreamHandlerProvider> sl =
1197 ServiceLoader.load(URLStreamHandlerProvider.class, cl);
1198 Iterator<URLStreamHandlerProvider> i = sl.iterator();
1199
1200 URLStreamHandlerProvider next = null;
1201
1202 private boolean getNext() {
1203 while (next == null) {
1204 try {
1205 if (!i.hasNext())
1206 return false;
1207 next = i.next();
1208 } catch (ServiceConfigurationError sce) {
1209 if (sce.getCause() instanceof SecurityException) {
1210 // Ignore security exceptions
1211 continue;
1212 }
1213 throw sce;
1226 URLStreamHandlerProvider n = next;
1227 next = null;
1228 return n;
1229 }
1230 };
1231 }
1232
1233 // Thread-local gate to prevent recursive provider lookups
1234 private static ThreadLocal<Object> gate = new ThreadLocal<>();
1235
1236 private static URLStreamHandler lookupViaProviders(final String protocol) {
1237 if (!sun.misc.VM.isBooted())
1238 return null;
1239
1240 if (gate.get() != null)
1241 throw new Error("Circular loading of URL stream handler providers detected");
1242
1243 gate.set(gate);
1244 try {
1245 return AccessController.doPrivileged(
1246 new PrivilegedAction<URLStreamHandler>() {
1247 public URLStreamHandler run() {
1248 Iterator<URLStreamHandlerProvider> itr = providers();
1249 while (itr.hasNext()) {
1250 URLStreamHandlerProvider f = itr.next();
1251 URLStreamHandler h = f.createURLStreamHandler(protocol);
1252 if (h != null)
1253 return h;
1254 }
1255 return null;
1256 }
1257 });
1258 } finally {
1259 gate.set(null);
1260 }
1261 }
1262
1263 private static final String[] NON_OVERRIDEABLE_PROTOCOLS = {"file", "jrt"};
1264 private static boolean isOverrideable(String protocol) {
1265 for (String p : NON_OVERRIDEABLE_PROTOCOLS)
1266 if (protocol.equalsIgnoreCase(p))
|
1141 private static class DefaultFactory implements URLStreamHandlerFactory {
1142 private static String PREFIX = "sun.net.www.protocol";
1143
1144 public URLStreamHandler createURLStreamHandler(String protocol) {
1145 String name = PREFIX + "." + protocol + ".Handler";
1146 try {
1147 Class<?> c = Class.forName(name);
1148 return (URLStreamHandler)c.newInstance();
1149 } catch (ClassNotFoundException x) {
1150 // ignore
1151 } catch (Exception e) {
1152 // For compatibility, all Exceptions are ignored.
1153 // any number of exceptions can get thrown here
1154 }
1155 return null;
1156 }
1157 }
1158
1159 private static URLStreamHandler lookupViaProperty(String protocol) {
1160 String packagePrefixList = java.security.AccessController.doPrivileged(
1161 new PrivilegedAction<>() {
1162 public String run() {
1163 return System.getProperty(protocolPathProp, "");
1164 }
1165 });
1166 String[] packagePrefixes = packagePrefixList.split("\\|");
1167
1168 URLStreamHandler handler = null;
1169 for (int i=0; handler == null && i<packagePrefixes.length; i++) {
1170 String packagePrefix = packagePrefixes[i].trim();
1171 try {
1172 String clsName = packagePrefix + "." + protocol + ".Handler";
1173 Class<?> cls = null;
1174 try {
1175 cls = Class.forName(clsName);
1176 } catch (ClassNotFoundException e) {
1177 ClassLoader cl = ClassLoader.getSystemClassLoader();
1178 if (cl != null) {
1179 cls = cl.loadClass(clsName);
1180 }
1181 }
1182 if (cls != null) {
1183 handler = (URLStreamHandler)cls.newInstance();
1184 }
1185 } catch (Exception e) {
1186 // any number of exceptions can get thrown here
1187 }
1188 }
1189 return handler;
1190 }
1191
1192 private static Iterator<URLStreamHandlerProvider> providers() {
1193 return new Iterator<>() {
1194
1195 ClassLoader cl = ClassLoader.getSystemClassLoader();
1196 ServiceLoader<URLStreamHandlerProvider> sl =
1197 ServiceLoader.load(URLStreamHandlerProvider.class, cl);
1198 Iterator<URLStreamHandlerProvider> i = sl.iterator();
1199
1200 URLStreamHandlerProvider next = null;
1201
1202 private boolean getNext() {
1203 while (next == null) {
1204 try {
1205 if (!i.hasNext())
1206 return false;
1207 next = i.next();
1208 } catch (ServiceConfigurationError sce) {
1209 if (sce.getCause() instanceof SecurityException) {
1210 // Ignore security exceptions
1211 continue;
1212 }
1213 throw sce;
1226 URLStreamHandlerProvider n = next;
1227 next = null;
1228 return n;
1229 }
1230 };
1231 }
1232
1233 // Thread-local gate to prevent recursive provider lookups
1234 private static ThreadLocal<Object> gate = new ThreadLocal<>();
1235
1236 private static URLStreamHandler lookupViaProviders(final String protocol) {
1237 if (!sun.misc.VM.isBooted())
1238 return null;
1239
1240 if (gate.get() != null)
1241 throw new Error("Circular loading of URL stream handler providers detected");
1242
1243 gate.set(gate);
1244 try {
1245 return AccessController.doPrivileged(
1246 new PrivilegedAction<>() {
1247 public URLStreamHandler run() {
1248 Iterator<URLStreamHandlerProvider> itr = providers();
1249 while (itr.hasNext()) {
1250 URLStreamHandlerProvider f = itr.next();
1251 URLStreamHandler h = f.createURLStreamHandler(protocol);
1252 if (h != null)
1253 return h;
1254 }
1255 return null;
1256 }
1257 });
1258 } finally {
1259 gate.set(null);
1260 }
1261 }
1262
1263 private static final String[] NON_OVERRIDEABLE_PROTOCOLS = {"file", "jrt"};
1264 private static boolean isOverrideable(String protocol) {
1265 for (String p : NON_OVERRIDEABLE_PROTOCOLS)
1266 if (protocol.equalsIgnoreCase(p))
|