aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/net/URL.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/net/URL.java')
-rw-r--r--libjava/java/net/URL.java59
1 files changed, 46 insertions, 13 deletions
diff --git a/libjava/java/net/URL.java b/libjava/java/net/URL.java
index 12c86914e30..2db8c4dd1cd 100644
--- a/libjava/java/net/URL.java
+++ b/libjava/java/net/URL.java
@@ -98,6 +98,14 @@ import java.util.StringTokenizer;
* <p>
* Please note that a protocol handler must be a subclass of
* URLStreamHandler.
+ * <p>
+ * Normally, this class caches protocol handlers. Once it finds a handler
+ * for a particular protocol, it never tries to look up a new handler
+ * again. However, if the system property
+ * gnu.java.net.nocache_protocol_handlers is set, then this
+ * caching behavior is disabled. This property is specific to this
+ * implementation. Sun's JDK may or may not do protocol caching, but it
+ * almost certainly does not examine this property.
*
* @author Aaron M. Renn <arenn@urbanophile.com>
* @author Warren Levy <warrenl@cygnus.com>
@@ -150,18 +158,32 @@ public final class URL implements Serializable
transient URLStreamHandler ph;
/**
+ * If an application installs its own protocol handler factory, this is
+ * where we keep track of it.
+ */
+ private static URLStreamHandlerFactory factory;
+
+ private static final long serialVersionUID = -7627629688361524110L;
+
+ /**
* This a table where we cache protocol handlers to avoid the overhead
* of looking them up each time.
*/
- private static Hashtable handlers = new Hashtable();
+ private static Hashtable ph_cache = new Hashtable();
/**
- * If an application installs its own protocol handler factory, this is
- * where we keep track of it.
+ * Whether or not to cache protocol handlers.
*/
- private static URLStreamHandlerFactory factory;
+ private static boolean cache_handlers;
- private static final long serialVersionUID = -7627629688361524110L;
+ static
+ {
+ String s = System.getProperty("gnu.java.net.nocache_protocol_handlers");
+ if (s == null)
+ cache_handlers = true;
+ else
+ cache_handlers = false;
+ }
/**
* Constructs a URL and loads a protocol handler for the values passed as
@@ -213,7 +235,7 @@ public final class URL implements Serializable
* @param port The port number to use, or -1 to use the protocol's default
* port
* @param file The "file" portion of the URL.
- * @param handler The protocol handler to use with this URL.
+ * @param ph The protocol handler to use with this URL.
*
* @exception MalformedURLException If no protocol handler can be loaded
* for the specified protocol.
@@ -222,8 +244,8 @@ public final class URL implements Serializable
*
* @since 1.2
*/
- public URL(String protocol, String host, int port, String file,
- URLStreamHandler ph)
+ public URL (String protocol, String host, int port, String file,
+ URLStreamHandler ph)
throws MalformedURLException
{
if (protocol == null)
@@ -320,7 +342,7 @@ public final class URL implements Serializable
*
* @param context The context in which to parse the specification
* @param spec The string to parse as an URL
- * @param handler The stream handler for the URL
+ * @param ph The stream handler for the URL
*
* @exception MalformedURLException If a protocol handler cannot be found
* or the URL cannot be parsed
@@ -718,18 +740,28 @@ public final class URL implements Serializable
return ph.toExternalForm(this);
}
+ /**
+ * This internal method is used in two different constructors to load
+ * a protocol handler for this URL.
+ *
+ * @param protocol The protocol to load a handler for
+ *
+ * @return A URLStreamHandler for this protocol, or null when not found.
+ */
private static synchronized URLStreamHandler
getURLStreamHandler (String protocol)
{
URLStreamHandler ph;
// See if a handler has been cached for this protocol.
- if ((ph = (URLStreamHandler) handlers.get(protocol)) != null)
+ if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null)
return ph;
// If a non-default factory has been set, use it to find the protocol.
if (factory != null)
- ph = factory.createURLStreamHandler(protocol);
+ {
+ ph = factory.createURLStreamHandler(protocol);
+ }
else if (protocol.equals ("core"))
{
ph = new gnu.gcj.protocol.core.Handler ();
@@ -780,9 +812,10 @@ public final class URL implements Serializable
}
// Update the hashtable with the new protocol handler.
- if (ph != null)
+ if (ph != null
+ && cache_handlers)
if (ph instanceof URLStreamHandler)
- handlers.put(protocol, ph);
+ ph_cache.put(protocol, ph);
else
ph = null;