jdk/src/share/classes/java/net/URL.java
changeset 10596 39b3a979e600
parent 5506 202f599c92aa
child 14197 1b78ddd3644e
equal deleted inserted replaced
10595:c5be3e19fbab 10596:39b3a979e600
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    25 
    25 
    26 package java.net;
    26 package java.net;
    27 
    27 
    28 import java.io.IOException;
    28 import java.io.IOException;
    29 import java.io.InputStream;
    29 import java.io.InputStream;
    30 import java.io.OutputStream;
       
    31 import java.util.Hashtable;
    30 import java.util.Hashtable;
    32 import java.util.StringTokenizer;
    31 import java.util.StringTokenizer;
    33 import sun.security.util.SecurityConstants;
    32 import sun.security.util.SecurityConstants;
    34 
    33 
    35 /**
    34 /**
  1111     }
  1110     }
  1112 
  1111 
  1113     /**
  1112     /**
  1114      * A table of protocol handlers.
  1113      * A table of protocol handlers.
  1115      */
  1114      */
  1116     static Hashtable handlers = new Hashtable();
  1115     static Hashtable<String,URLStreamHandler> handlers = new Hashtable<>();
  1117     private static Object streamHandlerLock = new Object();
  1116     private static Object streamHandlerLock = new Object();
  1118 
  1117 
  1119     /**
  1118     /**
  1120      * Returns the Stream Handler.
  1119      * Returns the Stream Handler.
  1121      * @param protocol the protocol to use
  1120      * @param protocol the protocol to use
  1122      */
  1121      */
  1123     static URLStreamHandler getURLStreamHandler(String protocol) {
  1122     static URLStreamHandler getURLStreamHandler(String protocol) {
  1124 
  1123 
  1125         URLStreamHandler handler = (URLStreamHandler)handlers.get(protocol);
  1124         URLStreamHandler handler = handlers.get(protocol);
  1126         if (handler == null) {
  1125         if (handler == null) {
  1127 
  1126 
  1128             boolean checkedWithFactory = false;
  1127             boolean checkedWithFactory = false;
  1129 
  1128 
  1130             // Use the factory (if any)
  1129             // Use the factory (if any)
  1158                     String packagePrefix =
  1157                     String packagePrefix =
  1159                       packagePrefixIter.nextToken().trim();
  1158                       packagePrefixIter.nextToken().trim();
  1160                     try {
  1159                     try {
  1161                         String clsName = packagePrefix + "." + protocol +
  1160                         String clsName = packagePrefix + "." + protocol +
  1162                           ".Handler";
  1161                           ".Handler";
  1163                         Class cls = null;
  1162                         Class<?> cls = null;
  1164                         try {
  1163                         try {
  1165                             cls = Class.forName(clsName);
  1164                             cls = Class.forName(clsName);
  1166                         } catch (ClassNotFoundException e) {
  1165                         } catch (ClassNotFoundException e) {
  1167                             ClassLoader cl = ClassLoader.getSystemClassLoader();
  1166                             ClassLoader cl = ClassLoader.getSystemClassLoader();
  1168                             if (cl != null) {
  1167                             if (cl != null) {
  1183 
  1182 
  1184                 URLStreamHandler handler2 = null;
  1183                 URLStreamHandler handler2 = null;
  1185 
  1184 
  1186                 // Check again with hashtable just in case another
  1185                 // Check again with hashtable just in case another
  1187                 // thread created a handler since we last checked
  1186                 // thread created a handler since we last checked
  1188                 handler2 = (URLStreamHandler)handlers.get(protocol);
  1187                 handler2 = handlers.get(protocol);
  1189 
  1188 
  1190                 if (handler2 != null) {
  1189                 if (handler2 != null) {
  1191                     return handler2;
  1190                     return handler2;
  1192                 }
  1191                 }
  1193 
  1192