< prev index next >

src/java.base/share/classes/java/net/URL.java

Print this page




1181             }
1182             SecurityManager security = System.getSecurityManager();
1183             if (security != null) {
1184                 security.checkSetFactory();
1185             }
1186             handlers.clear();
1187 
1188             // safe publication of URLStreamHandlerFactory with volatile write
1189             factory = fac;
1190         }
1191     }
1192 
1193     private static final URLStreamHandlerFactory defaultFactory = new DefaultFactory();
1194 
1195     private static class DefaultFactory implements URLStreamHandlerFactory {
1196         private static String PREFIX = "sun.net.www.protocol";
1197 
1198         public URLStreamHandler createURLStreamHandler(String protocol) {
1199             String name = PREFIX + "." + protocol + ".Handler";
1200             try {
1201                 Class<?> c = Class.forName(name);
1202                 return (URLStreamHandler)c.newInstance();

1203             } catch (ClassNotFoundException x) {
1204                 // ignore
1205             } catch (Exception e) {
1206                 // For compatibility, all Exceptions are ignored.
1207                 // any number of exceptions can get thrown here
1208             }
1209             return null;
1210         }
1211     }
1212 
1213     private static URLStreamHandler lookupViaProperty(String protocol) {
1214         String packagePrefixList =
1215                 GetPropertyAction.getProperty(protocolPathProp);
1216         if (packagePrefixList == null) {
1217             // not set
1218             return null;
1219         }
1220 
1221         String[] packagePrefixes = packagePrefixList.split("\\|");
1222         URLStreamHandler handler = null;
1223         for (int i=0; handler == null && i<packagePrefixes.length; i++) {
1224             String packagePrefix = packagePrefixes[i].trim();
1225             try {
1226                 String clsName = packagePrefix + "." + protocol + ".Handler";
1227                 Class<?> cls = null;
1228                 try {
1229                     cls = Class.forName(clsName);
1230                 } catch (ClassNotFoundException e) {
1231                     ClassLoader cl = ClassLoader.getSystemClassLoader();
1232                     if (cl != null) {
1233                         cls = cl.loadClass(clsName);
1234                     }
1235                 }
1236                 if (cls != null) {
1237                     handler = (URLStreamHandler)cls.newInstance();


1238                 }
1239             } catch (Exception e) {
1240                 // any number of exceptions can get thrown here
1241             }
1242         }
1243         return handler;
1244     }
1245 
1246     private static Iterator<URLStreamHandlerProvider> providers() {
1247         return new Iterator<>() {
1248 
1249             ClassLoader cl = ClassLoader.getSystemClassLoader();
1250             ServiceLoader<URLStreamHandlerProvider> sl =
1251                     ServiceLoader.load(URLStreamHandlerProvider.class, cl);
1252             Iterator<URLStreamHandlerProvider> i = sl.iterator();
1253 
1254             URLStreamHandlerProvider next = null;
1255 
1256             private boolean getNext() {
1257                 while (next == null) {




1181             }
1182             SecurityManager security = System.getSecurityManager();
1183             if (security != null) {
1184                 security.checkSetFactory();
1185             }
1186             handlers.clear();
1187 
1188             // safe publication of URLStreamHandlerFactory with volatile write
1189             factory = fac;
1190         }
1191     }
1192 
1193     private static final URLStreamHandlerFactory defaultFactory = new DefaultFactory();
1194 
1195     private static class DefaultFactory implements URLStreamHandlerFactory {
1196         private static String PREFIX = "sun.net.www.protocol";
1197 
1198         public URLStreamHandler createURLStreamHandler(String protocol) {
1199             String name = PREFIX + "." + protocol + ".Handler";
1200             try {
1201                 @SuppressWarnings("deprecation")
1202                 Object o = Class.forName(name).newInstance();
1203                 return (URLStreamHandler)o;
1204             } catch (ClassNotFoundException x) {
1205                 // ignore
1206             } catch (Exception e) {
1207                 // For compatibility, all Exceptions are ignored.
1208                 // any number of exceptions can get thrown here
1209             }
1210             return null;
1211         }
1212     }
1213 
1214     private static URLStreamHandler lookupViaProperty(String protocol) {
1215         String packagePrefixList =
1216                 GetPropertyAction.getProperty(protocolPathProp);
1217         if (packagePrefixList == null) {
1218             // not set
1219             return null;
1220         }
1221 
1222         String[] packagePrefixes = packagePrefixList.split("\\|");
1223         URLStreamHandler handler = null;
1224         for (int i=0; handler == null && i<packagePrefixes.length; i++) {
1225             String packagePrefix = packagePrefixes[i].trim();
1226             try {
1227                 String clsName = packagePrefix + "." + protocol + ".Handler";
1228                 Class<?> cls = null;
1229                 try {
1230                     cls = Class.forName(clsName);
1231                 } catch (ClassNotFoundException e) {
1232                     ClassLoader cl = ClassLoader.getSystemClassLoader();
1233                     if (cl != null) {
1234                         cls = cl.loadClass(clsName);
1235                     }
1236                 }
1237                 if (cls != null) {
1238                     @SuppressWarnings("deprecation")
1239                     Object tmp = cls.newInstance();
1240                     handler = (URLStreamHandler)tmp;
1241                 }
1242             } catch (Exception e) {
1243                 // any number of exceptions can get thrown here
1244             }
1245         }
1246         return handler;
1247     }
1248 
1249     private static Iterator<URLStreamHandlerProvider> providers() {
1250         return new Iterator<>() {
1251 
1252             ClassLoader cl = ClassLoader.getSystemClassLoader();
1253             ServiceLoader<URLStreamHandlerProvider> sl =
1254                     ServiceLoader.load(URLStreamHandlerProvider.class, cl);
1255             Iterator<URLStreamHandlerProvider> i = sl.iterator();
1256 
1257             URLStreamHandlerProvider next = null;
1258 
1259             private boolean getNext() {
1260                 while (next == null) {


< prev index next >