It will be easier to get the logic from inside the URLSteamHandler than to try to mimic it jdk7-b147
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 16 Dec 2012 20:13:00 +0100
branchjdk7-b147
changeset 327444cfb098f1a
parent 263 13b21fcbadbe
child 333 4a653c70ca20
child 414 0dab62955440
It will be easier to get the logic from inside the URLSteamHandler than to try to mimic it
emul/src/main/java/java/net/URLStreamHandler.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/src/main/java/java/net/URLStreamHandler.java	Sun Dec 16 20:13:00 2012 +0100
     1.3 @@ -0,0 +1,590 @@
     1.4 +/*
     1.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package java.net;
    1.30 +
    1.31 +import java.io.IOException;
    1.32 +import java.io.InputStream;
    1.33 +import java.io.File;
    1.34 +import java.io.OutputStream;
    1.35 +import java.util.Hashtable;
    1.36 +import sun.net.util.IPAddressUtil;
    1.37 +import sun.net.www.ParseUtil;
    1.38 +
    1.39 +/**
    1.40 + * The abstract class <code>URLStreamHandler</code> is the common
    1.41 + * superclass for all stream protocol handlers. A stream protocol
    1.42 + * handler knows how to make a connection for a particular protocol
    1.43 + * type, such as <code>http</code>, <code>ftp</code>, or
    1.44 + * <code>gopher</code>.
    1.45 + * <p>
    1.46 + * In most cases, an instance of a <code>URLStreamHandler</code>
    1.47 + * subclass is not created directly by an application. Rather, the
    1.48 + * first time a protocol name is encountered when constructing a
    1.49 + * <code>URL</code>, the appropriate stream protocol handler is
    1.50 + * automatically loaded.
    1.51 + *
    1.52 + * @author  James Gosling
    1.53 + * @see     java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
    1.54 + * @since   JDK1.0
    1.55 + */
    1.56 +public abstract class URLStreamHandler {
    1.57 +    /**
    1.58 +     * Opens a connection to the object referenced by the
    1.59 +     * <code>URL</code> argument.
    1.60 +     * This method should be overridden by a subclass.
    1.61 +     *
    1.62 +     * <p>If for the handler's protocol (such as HTTP or JAR), there
    1.63 +     * exists a public, specialized URLConnection subclass belonging
    1.64 +     * to one of the following packages or one of their subpackages:
    1.65 +     * java.lang, java.io, java.util, java.net, the connection
    1.66 +     * returned will be of that subclass. For example, for HTTP an
    1.67 +     * HttpURLConnection will be returned, and for JAR a
    1.68 +     * JarURLConnection will be returned.
    1.69 +     *
    1.70 +     * @param      u   the URL that this connects to.
    1.71 +     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
    1.72 +     * @exception  IOException  if an I/O error occurs while opening the
    1.73 +     *               connection.
    1.74 +     */
    1.75 +    abstract protected URLConnection openConnection(URL u) throws IOException;
    1.76 +
    1.77 +    /**
    1.78 +     * Same as openConnection(URL), except that the connection will be
    1.79 +     * made through the specified proxy; Protocol handlers that do not
    1.80 +     * support proxying will ignore the proxy parameter and make a
    1.81 +     * normal connection.
    1.82 +     *
    1.83 +     * Calling this method preempts the system's default ProxySelector
    1.84 +     * settings.
    1.85 +     *
    1.86 +     * @param      u   the URL that this connects to.
    1.87 +     * @param      p   the proxy through which the connection will be made.
    1.88 +     *                 If direct connection is desired, Proxy.NO_PROXY
    1.89 +     *                 should be specified.
    1.90 +     * @return     a <code>URLConnection</code> object for the <code>URL</code>.
    1.91 +     * @exception  IOException  if an I/O error occurs while opening the
    1.92 +     *               connection.
    1.93 +     * @exception  IllegalArgumentException if either u or p is null,
    1.94 +     *               or p has the wrong type.
    1.95 +     * @exception  UnsupportedOperationException if the subclass that
    1.96 +     *               implements the protocol doesn't support this method.
    1.97 +     * @since      1.5
    1.98 +     */
    1.99 +    protected URLConnection openConnection(URL u, Proxy p) throws IOException {
   1.100 +        throw new UnsupportedOperationException("Method not implemented.");
   1.101 +    }
   1.102 +
   1.103 +    /**
   1.104 +     * Parses the string representation of a <code>URL</code> into a
   1.105 +     * <code>URL</code> object.
   1.106 +     * <p>
   1.107 +     * If there is any inherited context, then it has already been
   1.108 +     * copied into the <code>URL</code> argument.
   1.109 +     * <p>
   1.110 +     * The <code>parseURL</code> method of <code>URLStreamHandler</code>
   1.111 +     * parses the string representation as if it were an
   1.112 +     * <code>http</code> specification. Most URL protocol families have a
   1.113 +     * similar parsing. A stream protocol handler for a protocol that has
   1.114 +     * a different syntax must override this routine.
   1.115 +     *
   1.116 +     * @param   u       the <code>URL</code> to receive the result of parsing
   1.117 +     *                  the spec.
   1.118 +     * @param   spec    the <code>String</code> representing the URL that
   1.119 +     *                  must be parsed.
   1.120 +     * @param   start   the character index at which to begin parsing. This is
   1.121 +     *                  just past the '<code>:</code>' (if there is one) that
   1.122 +     *                  specifies the determination of the protocol name.
   1.123 +     * @param   limit   the character position to stop parsing at. This is the
   1.124 +     *                  end of the string or the position of the
   1.125 +     *                  "<code>#</code>" character, if present. All information
   1.126 +     *                  after the sharp sign indicates an anchor.
   1.127 +     */
   1.128 +    protected void parseURL(URL u, String spec, int start, int limit) {
   1.129 +        // These fields may receive context content if this was relative URL
   1.130 +        String protocol = u.getProtocol();
   1.131 +        String authority = u.getAuthority();
   1.132 +        String userInfo = u.getUserInfo();
   1.133 +        String host = u.getHost();
   1.134 +        int port = u.getPort();
   1.135 +        String path = u.getPath();
   1.136 +        String query = u.getQuery();
   1.137 +
   1.138 +        // This field has already been parsed
   1.139 +        String ref = u.getRef();
   1.140 +
   1.141 +        boolean isRelPath = false;
   1.142 +        boolean queryOnly = false;
   1.143 +
   1.144 +// FIX: should not assume query if opaque
   1.145 +        // Strip off the query part
   1.146 +        if (start < limit) {
   1.147 +            int queryStart = spec.indexOf('?');
   1.148 +            queryOnly = queryStart == start;
   1.149 +            if ((queryStart != -1) && (queryStart < limit)) {
   1.150 +                query = spec.substring(queryStart+1, limit);
   1.151 +                if (limit > queryStart)
   1.152 +                    limit = queryStart;
   1.153 +                spec = spec.substring(0, queryStart);
   1.154 +            }
   1.155 +        }
   1.156 +
   1.157 +        int i = 0;
   1.158 +        // Parse the authority part if any
   1.159 +        boolean isUNCName = (start <= limit - 4) &&
   1.160 +                        (spec.charAt(start) == '/') &&
   1.161 +                        (spec.charAt(start + 1) == '/') &&
   1.162 +                        (spec.charAt(start + 2) == '/') &&
   1.163 +                        (spec.charAt(start + 3) == '/');
   1.164 +        if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
   1.165 +            (spec.charAt(start + 1) == '/')) {
   1.166 +            start += 2;
   1.167 +            i = spec.indexOf('/', start);
   1.168 +            if (i < 0) {
   1.169 +                i = spec.indexOf('?', start);
   1.170 +                if (i < 0)
   1.171 +                    i = limit;
   1.172 +            }
   1.173 +
   1.174 +            host = authority = spec.substring(start, i);
   1.175 +
   1.176 +            int ind = authority.indexOf('@');
   1.177 +            if (ind != -1) {
   1.178 +                userInfo = authority.substring(0, ind);
   1.179 +                host = authority.substring(ind+1);
   1.180 +            } else {
   1.181 +                userInfo = null;
   1.182 +            }
   1.183 +            if (host != null) {
   1.184 +                // If the host is surrounded by [ and ] then its an IPv6
   1.185 +                // literal address as specified in RFC2732
   1.186 +                if (host.length()>0 && (host.charAt(0) == '[')) {
   1.187 +                    if ((ind = host.indexOf(']')) > 2) {
   1.188 +
   1.189 +                        String nhost = host ;
   1.190 +                        host = nhost.substring(0,ind+1);
   1.191 +                        if (!IPAddressUtil.
   1.192 +                            isIPv6LiteralAddress(host.substring(1, ind))) {
   1.193 +                            throw new IllegalArgumentException(
   1.194 +                                "Invalid host: "+ host);
   1.195 +                        }
   1.196 +
   1.197 +                        port = -1 ;
   1.198 +                        if (nhost.length() > ind+1) {
   1.199 +                            if (nhost.charAt(ind+1) == ':') {
   1.200 +                                ++ind ;
   1.201 +                                // port can be null according to RFC2396
   1.202 +                                if (nhost.length() > (ind + 1)) {
   1.203 +                                    port = Integer.parseInt(nhost.substring(ind+1));
   1.204 +                                }
   1.205 +                            } else {
   1.206 +                                throw new IllegalArgumentException(
   1.207 +                                    "Invalid authority field: " + authority);
   1.208 +                            }
   1.209 +                        }
   1.210 +                    } else {
   1.211 +                        throw new IllegalArgumentException(
   1.212 +                            "Invalid authority field: " + authority);
   1.213 +                    }
   1.214 +                } else {
   1.215 +                    ind = host.indexOf(':');
   1.216 +                    port = -1;
   1.217 +                    if (ind >= 0) {
   1.218 +                        // port can be null according to RFC2396
   1.219 +                        if (host.length() > (ind + 1)) {
   1.220 +                            port = Integer.parseInt(host.substring(ind + 1));
   1.221 +                        }
   1.222 +                        host = host.substring(0, ind);
   1.223 +                    }
   1.224 +                }
   1.225 +            } else {
   1.226 +                host = "";
   1.227 +            }
   1.228 +            if (port < -1)
   1.229 +                throw new IllegalArgumentException("Invalid port number :" +
   1.230 +                                                   port);
   1.231 +            start = i;
   1.232 +            // If the authority is defined then the path is defined by the
   1.233 +            // spec only; See RFC 2396 Section 5.2.4.
   1.234 +            if (authority != null && authority.length() > 0)
   1.235 +                path = "";
   1.236 +        }
   1.237 +
   1.238 +        if (host == null) {
   1.239 +            host = "";
   1.240 +        }
   1.241 +
   1.242 +        // Parse the file path if any
   1.243 +        if (start < limit) {
   1.244 +            if (spec.charAt(start) == '/') {
   1.245 +                path = spec.substring(start, limit);
   1.246 +            } else if (path != null && path.length() > 0) {
   1.247 +                isRelPath = true;
   1.248 +                int ind = path.lastIndexOf('/');
   1.249 +                String seperator = "";
   1.250 +                if (ind == -1 && authority != null)
   1.251 +                    seperator = "/";
   1.252 +                path = path.substring(0, ind + 1) + seperator +
   1.253 +                         spec.substring(start, limit);
   1.254 +
   1.255 +            } else {
   1.256 +                String seperator = (authority != null) ? "/" : "";
   1.257 +                path = seperator + spec.substring(start, limit);
   1.258 +            }
   1.259 +        } else if (queryOnly && path != null) {
   1.260 +            int ind = path.lastIndexOf('/');
   1.261 +            if (ind < 0)
   1.262 +                ind = 0;
   1.263 +            path = path.substring(0, ind) + "/";
   1.264 +        }
   1.265 +        if (path == null)
   1.266 +            path = "";
   1.267 +
   1.268 +        if (isRelPath) {
   1.269 +            // Remove embedded /./
   1.270 +            while ((i = path.indexOf("/./")) >= 0) {
   1.271 +                path = path.substring(0, i) + path.substring(i + 2);
   1.272 +            }
   1.273 +            // Remove embedded /../ if possible
   1.274 +            i = 0;
   1.275 +            while ((i = path.indexOf("/../", i)) >= 0) {
   1.276 +                /*
   1.277 +                 * A "/../" will cancel the previous segment and itself,
   1.278 +                 * unless that segment is a "/../" itself
   1.279 +                 * i.e. "/a/b/../c" becomes "/a/c"
   1.280 +                 * but "/../../a" should stay unchanged
   1.281 +                 */
   1.282 +                if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 &&
   1.283 +                    (path.indexOf("/../", limit) != 0)) {
   1.284 +                    path = path.substring(0, limit) + path.substring(i + 3);
   1.285 +                    i = 0;
   1.286 +                } else {
   1.287 +                    i = i + 3;
   1.288 +                }
   1.289 +            }
   1.290 +            // Remove trailing .. if possible
   1.291 +            while (path.endsWith("/..")) {
   1.292 +                i = path.indexOf("/..");
   1.293 +                if ((limit = path.lastIndexOf('/', i - 1)) >= 0) {
   1.294 +                    path = path.substring(0, limit+1);
   1.295 +                } else {
   1.296 +                    break;
   1.297 +                }
   1.298 +            }
   1.299 +            // Remove starting .
   1.300 +            if (path.startsWith("./") && path.length() > 2)
   1.301 +                path = path.substring(2);
   1.302 +
   1.303 +            // Remove trailing .
   1.304 +            if (path.endsWith("/."))
   1.305 +                path = path.substring(0, path.length() -1);
   1.306 +        }
   1.307 +
   1.308 +        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
   1.309 +    }
   1.310 +
   1.311 +    /**
   1.312 +     * Returns the default port for a URL parsed by this handler. This method
   1.313 +     * is meant to be overidden by handlers with default port numbers.
   1.314 +     * @return the default port for a <code>URL</code> parsed by this handler.
   1.315 +     * @since 1.3
   1.316 +     */
   1.317 +    protected int getDefaultPort() {
   1.318 +        return -1;
   1.319 +    }
   1.320 +
   1.321 +    /**
   1.322 +     * Provides the default equals calculation. May be overidden by handlers
   1.323 +     * for other protocols that have different requirements for equals().
   1.324 +     * This method requires that none of its arguments is null. This is
   1.325 +     * guaranteed by the fact that it is only called by java.net.URL class.
   1.326 +     * @param u1 a URL object
   1.327 +     * @param u2 a URL object
   1.328 +     * @return <tt>true</tt> if the two urls are
   1.329 +     * considered equal, ie. they refer to the same
   1.330 +     * fragment in the same file.
   1.331 +     * @since 1.3
   1.332 +     */
   1.333 +    protected boolean equals(URL u1, URL u2) {
   1.334 +        String ref1 = u1.getRef();
   1.335 +        String ref2 = u2.getRef();
   1.336 +        return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
   1.337 +               sameFile(u1, u2);
   1.338 +    }
   1.339 +
   1.340 +    /**
   1.341 +     * Provides the default hash calculation. May be overidden by handlers for
   1.342 +     * other protocols that have different requirements for hashCode
   1.343 +     * calculation.
   1.344 +     * @param u a URL object
   1.345 +     * @return an <tt>int</tt> suitable for hash table indexing
   1.346 +     * @since 1.3
   1.347 +     */
   1.348 +    protected int hashCode(URL u) {
   1.349 +        int h = 0;
   1.350 +
   1.351 +        // Generate the protocol part.
   1.352 +        String protocol = u.getProtocol();
   1.353 +        if (protocol != null)
   1.354 +            h += protocol.hashCode();
   1.355 +
   1.356 +        // Generate the host part.
   1.357 +        InetAddress addr = getHostAddress(u);
   1.358 +        if (addr != null) {
   1.359 +            h += addr.hashCode();
   1.360 +        } else {
   1.361 +            String host = u.getHost();
   1.362 +            if (host != null)
   1.363 +                h += host.toLowerCase().hashCode();
   1.364 +        }
   1.365 +
   1.366 +        // Generate the file part.
   1.367 +        String file = u.getFile();
   1.368 +        if (file != null)
   1.369 +            h += file.hashCode();
   1.370 +
   1.371 +        // Generate the port part.
   1.372 +        if (u.getPort() == -1)
   1.373 +            h += getDefaultPort();
   1.374 +        else
   1.375 +            h += u.getPort();
   1.376 +
   1.377 +        // Generate the ref part.
   1.378 +        String ref = u.getRef();
   1.379 +        if (ref != null)
   1.380 +            h += ref.hashCode();
   1.381 +
   1.382 +        return h;
   1.383 +    }
   1.384 +
   1.385 +    /**
   1.386 +     * Compare two urls to see whether they refer to the same file,
   1.387 +     * i.e., having the same protocol, host, port, and path.
   1.388 +     * This method requires that none of its arguments is null. This is
   1.389 +     * guaranteed by the fact that it is only called indirectly
   1.390 +     * by java.net.URL class.
   1.391 +     * @param u1 a URL object
   1.392 +     * @param u2 a URL object
   1.393 +     * @return true if u1 and u2 refer to the same file
   1.394 +     * @since 1.3
   1.395 +     */
   1.396 +    protected boolean sameFile(URL u1, URL u2) {
   1.397 +        // Compare the protocols.
   1.398 +        if (!((u1.getProtocol() == u2.getProtocol()) ||
   1.399 +              (u1.getProtocol() != null &&
   1.400 +               u1.getProtocol().equalsIgnoreCase(u2.getProtocol()))))
   1.401 +            return false;
   1.402 +
   1.403 +        // Compare the files.
   1.404 +        if (!(u1.getFile() == u2.getFile() ||
   1.405 +              (u1.getFile() != null && u1.getFile().equals(u2.getFile()))))
   1.406 +            return false;
   1.407 +
   1.408 +        // Compare the ports.
   1.409 +        int port1, port2;
   1.410 +        port1 = (u1.getPort() != -1) ? u1.getPort() : u1.handler.getDefaultPort();
   1.411 +        port2 = (u2.getPort() != -1) ? u2.getPort() : u2.handler.getDefaultPort();
   1.412 +        if (port1 != port2)
   1.413 +            return false;
   1.414 +
   1.415 +        // Compare the hosts.
   1.416 +        if (!hostsEqual(u1, u2))
   1.417 +            return false;
   1.418 +
   1.419 +        return true;
   1.420 +    }
   1.421 +
   1.422 +    /**
   1.423 +     * Get the IP address of our host. An empty host field or a DNS failure
   1.424 +     * will result in a null return.
   1.425 +     *
   1.426 +     * @param u a URL object
   1.427 +     * @return an <code>InetAddress</code> representing the host
   1.428 +     * IP address.
   1.429 +     * @since 1.3
   1.430 +     */
   1.431 +    protected synchronized InetAddress getHostAddress(URL u) {
   1.432 +        if (u.hostAddress != null)
   1.433 +            return u.hostAddress;
   1.434 +
   1.435 +        String host = u.getHost();
   1.436 +        if (host == null || host.equals("")) {
   1.437 +            return null;
   1.438 +        } else {
   1.439 +            try {
   1.440 +                u.hostAddress = InetAddress.getByName(host);
   1.441 +            } catch (UnknownHostException ex) {
   1.442 +                return null;
   1.443 +            } catch (SecurityException se) {
   1.444 +                return null;
   1.445 +            }
   1.446 +        }
   1.447 +        return u.hostAddress;
   1.448 +    }
   1.449 +
   1.450 +    /**
   1.451 +     * Compares the host components of two URLs.
   1.452 +     * @param u1 the URL of the first host to compare
   1.453 +     * @param u2 the URL of the second host to compare
   1.454 +     * @return  <tt>true</tt> if and only if they
   1.455 +     * are equal, <tt>false</tt> otherwise.
   1.456 +     * @since 1.3
   1.457 +     */
   1.458 +    protected boolean hostsEqual(URL u1, URL u2) {
   1.459 +        InetAddress a1 = getHostAddress(u1);
   1.460 +        InetAddress a2 = getHostAddress(u2);
   1.461 +        // if we have internet address for both, compare them
   1.462 +        if (a1 != null && a2 != null) {
   1.463 +            return a1.equals(a2);
   1.464 +        // else, if both have host names, compare them
   1.465 +        } else if (u1.getHost() != null && u2.getHost() != null)
   1.466 +            return u1.getHost().equalsIgnoreCase(u2.getHost());
   1.467 +         else
   1.468 +            return u1.getHost() == null && u2.getHost() == null;
   1.469 +    }
   1.470 +
   1.471 +    /**
   1.472 +     * Converts a <code>URL</code> of a specific protocol to a
   1.473 +     * <code>String</code>.
   1.474 +     *
   1.475 +     * @param   u   the URL.
   1.476 +     * @return  a string representation of the <code>URL</code> argument.
   1.477 +     */
   1.478 +    protected String toExternalForm(URL u) {
   1.479 +
   1.480 +        // pre-compute length of StringBuffer
   1.481 +        int len = u.getProtocol().length() + 1;
   1.482 +        if (u.getAuthority() != null && u.getAuthority().length() > 0)
   1.483 +            len += 2 + u.getAuthority().length();
   1.484 +        if (u.getPath() != null) {
   1.485 +            len += u.getPath().length();
   1.486 +        }
   1.487 +        if (u.getQuery() != null) {
   1.488 +            len += 1 + u.getQuery().length();
   1.489 +        }
   1.490 +        if (u.getRef() != null)
   1.491 +            len += 1 + u.getRef().length();
   1.492 +
   1.493 +        StringBuffer result = new StringBuffer(len);
   1.494 +        result.append(u.getProtocol());
   1.495 +        result.append(":");
   1.496 +        if (u.getAuthority() != null && u.getAuthority().length() > 0) {
   1.497 +            result.append("//");
   1.498 +            result.append(u.getAuthority());
   1.499 +        }
   1.500 +        if (u.getPath() != null) {
   1.501 +            result.append(u.getPath());
   1.502 +        }
   1.503 +        if (u.getQuery() != null) {
   1.504 +            result.append('?');
   1.505 +            result.append(u.getQuery());
   1.506 +        }
   1.507 +        if (u.getRef() != null) {
   1.508 +            result.append("#");
   1.509 +            result.append(u.getRef());
   1.510 +        }
   1.511 +        return result.toString();
   1.512 +    }
   1.513 +
   1.514 +    /**
   1.515 +     * Sets the fields of the <code>URL</code> argument to the indicated values.
   1.516 +     * Only classes derived from URLStreamHandler are supposed to be able
   1.517 +     * to call the set method on a URL.
   1.518 +     *
   1.519 +     * @param   u         the URL to modify.
   1.520 +     * @param   protocol  the protocol name.
   1.521 +     * @param   host      the remote host value for the URL.
   1.522 +     * @param   port      the port on the remote machine.
   1.523 +     * @param   authority the authority part for the URL.
   1.524 +     * @param   userInfo the userInfo part of the URL.
   1.525 +     * @param   path      the path component of the URL.
   1.526 +     * @param   query     the query part for the URL.
   1.527 +     * @param   ref       the reference.
   1.528 +     * @exception       SecurityException       if the protocol handler of the URL is
   1.529 +     *                                  different from this one
   1.530 +     * @see     java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
   1.531 +     * @since 1.3
   1.532 +     */
   1.533 +       protected void setURL(URL u, String protocol, String host, int port,
   1.534 +                             String authority, String userInfo, String path,
   1.535 +                             String query, String ref) {
   1.536 +        if (this != u.handler) {
   1.537 +            throw new SecurityException("handler for url different from " +
   1.538 +                                        "this handler");
   1.539 +        }
   1.540 +        // ensure that no one can reset the protocol on a given URL.
   1.541 +        u.set(u.getProtocol(), host, port, authority, userInfo, path, query, ref);
   1.542 +    }
   1.543 +
   1.544 +    /**
   1.545 +     * Sets the fields of the <code>URL</code> argument to the indicated values.
   1.546 +     * Only classes derived from URLStreamHandler are supposed to be able
   1.547 +     * to call the set method on a URL.
   1.548 +     *
   1.549 +     * @param   u         the URL to modify.
   1.550 +     * @param   protocol  the protocol name. This value is ignored since 1.2.
   1.551 +     * @param   host      the remote host value for the URL.
   1.552 +     * @param   port      the port on the remote machine.
   1.553 +     * @param   file      the file.
   1.554 +     * @param   ref       the reference.
   1.555 +     * @exception       SecurityException       if the protocol handler of the URL is
   1.556 +     *                                  different from this one
   1.557 +     * @deprecated Use setURL(URL, String, String, int, String, String, String,
   1.558 +     *             String);
   1.559 +     */
   1.560 +    @Deprecated
   1.561 +    protected void setURL(URL u, String protocol, String host, int port,
   1.562 +                          String file, String ref) {
   1.563 +        /*
   1.564 +         * Only old URL handlers call this, so assume that the host
   1.565 +         * field might contain "user:passwd@host". Fix as necessary.
   1.566 +         */
   1.567 +        String authority = null;
   1.568 +        String userInfo = null;
   1.569 +        if (host != null && host.length() != 0) {
   1.570 +            authority = (port == -1) ? host : host + ":" + port;
   1.571 +            int at = host.lastIndexOf('@');
   1.572 +            if (at != -1) {
   1.573 +                userInfo = host.substring(0, at);
   1.574 +                host = host.substring(at+1);
   1.575 +            }
   1.576 +        }
   1.577 +
   1.578 +        /*
   1.579 +         * Assume file might contain query part. Fix as necessary.
   1.580 +         */
   1.581 +        String path = null;
   1.582 +        String query = null;
   1.583 +        if (file != null) {
   1.584 +            int q = file.lastIndexOf('?');
   1.585 +            if (q != -1) {
   1.586 +                query = file.substring(q+1);
   1.587 +                path = file.substring(0, q);
   1.588 +            } else
   1.589 +                path = file;
   1.590 +        }
   1.591 +        setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
   1.592 +    }
   1.593 +}