2362N/A * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The abstract class <code>URLStreamHandler</code> is the common 0N/A * superclass for all stream protocol handlers. A stream protocol 0N/A * handler knows how to make a connection for a particular protocol 0N/A * type, such as <code>http</code>, <code>ftp</code>, or 0N/A * <code>gopher</code>. 0N/A * In most cases, an instance of a <code>URLStreamHandler</code> 0N/A * subclass is not created directly by an application. Rather, the 0N/A * first time a protocol name is encountered when constructing a 0N/A * <code>URL</code>, the appropriate stream protocol handler is 0N/A * automatically loaded. 0N/A * @author James Gosling 0N/A * @see java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String) 0N/A * Opens a connection to the object referenced by the 0N/A * <code>URL</code> argument. 0N/A * This method should be overridden by a subclass. 0N/A * <p>If for the handler's protocol (such as HTTP or JAR), there 0N/A * exists a public, specialized URLConnection subclass belonging 0N/A * to one of the following packages or one of their subpackages: 0N/A * java.lang, java.io, java.util, java.net, the connection 0N/A * returned will be of that subclass. For example, for HTTP an 0N/A * HttpURLConnection will be returned, and for JAR a 0N/A * JarURLConnection will be returned. 0N/A * @param u the URL that this connects to. 0N/A * @return a <code>URLConnection</code> object for the <code>URL</code>. 0N/A * @exception IOException if an I/O error occurs while opening the 0N/A * Same as openConnection(URL), except that the connection will be 0N/A * made through the specified proxy; Protocol handlers that do not 0N/A * support proxying will ignore the proxy parameter and make a 0N/A * normal connection. 0N/A * Calling this method preempts the system's default ProxySelector 0N/A * @param u the URL that this connects to. 0N/A * @param p the proxy through which the connection will be made. 0N/A * If direct connection is desired, Proxy.NO_PROXY 0N/A * should be specified. 0N/A * @return a <code>URLConnection</code> object for the <code>URL</code>. 0N/A * @exception IOException if an I/O error occurs while opening the 0N/A * @exception IllegalArgumentException if either u or p is null, 0N/A * or p has the wrong type. 0N/A * @exception UnsupportedOperationException if the subclass that 0N/A * implements the protocol doesn't support this method. 0N/A * Parses the string representation of a <code>URL</code> into a 0N/A * <code>URL</code> object. 0N/A * If there is any inherited context, then it has already been 0N/A * copied into the <code>URL</code> argument. 0N/A * The <code>parseURL</code> method of <code>URLStreamHandler</code> 0N/A * parses the string representation as if it were an 0N/A * <code>http</code> specification. Most URL protocol families have a 0N/A * similar parsing. A stream protocol handler for a protocol that has 0N/A * a different syntax must override this routine. 0N/A * @param u the <code>URL</code> to receive the result of parsing 0N/A * @param spec the <code>String</code> representing the URL that 0N/A * @param start the character index at which to begin parsing. This is 0N/A * just past the '<code>:</code>' (if there is one) that 0N/A * specifies the determination of the protocol name. 0N/A * @param limit the character position to stop parsing at. This is the 0N/A * end of the string or the position of the 0N/A * "<code>#</code>" character, if present. All information 0N/A * after the sharp sign indicates an anchor. 0N/A // These fields may receive context content if this was relative URL 0N/A // This field has already been parsed 0N/A// FIX: should not assume query if opaque 0N/A // Strip off the query part 0N/A // Parse the authority part if any 0N/A // If the host is surrounded by [ and ] then its an IPv6 0N/A // literal address as specified in RFC2732 0N/A // port can be null according to RFC2396 0N/A // port can be null according to RFC2396 0N/A // If the authority is defined then the path is defined by the 0N/A // spec only; See RFC 2396 Section 5.2.4. 0N/A // Parse the file path if any 0N/A // Remove embedded /./ 0N/A // Remove embedded /../ if possible 0N/A * A "/../" will cancel the previous segment and itself, 0N/A * unless that segment is a "/../" itself 0N/A * i.e. "/a/b/../c" becomes "/a/c" 0N/A * but "/../../a" should stay unchanged 0N/A // Remove trailing .. if possible 0N/A // Remove starting . 0N/A // Remove trailing . 0N/A * Returns the default port for a URL parsed by this handler. This method 0N/A * is meant to be overidden by handlers with default port numbers. 0N/A * @return the default port for a <code>URL</code> parsed by this handler. 0N/A * Provides the default equals calculation. May be overidden by handlers 0N/A * for other protocols that have different requirements for equals(). 0N/A * This method requires that none of its arguments is null. This is 0N/A * guaranteed by the fact that it is only called by java.net.URL class. 0N/A * @param u1 a URL object 0N/A * @param u2 a URL object 0N/A * @return <tt>true</tt> if the two urls are 0N/A * considered equal, ie. they refer to the same 0N/A * fragment in the same file. 0N/A * Provides the default hash calculation. May be overidden by handlers for 0N/A * other protocols that have different requirements for hashCode 0N/A * @param u a URL object 0N/A * @return an <tt>int</tt> suitable for hash table indexing 0N/A // Generate the protocol part. 0N/A // Generate the host part. 0N/A // Generate the file part. 0N/A // Generate the port part. 0N/A // Generate the ref part. 0N/A * Compare two urls to see whether they refer to the same file, 0N/A * i.e., having the same protocol, host, port, and path. 0N/A * This method requires that none of its arguments is null. This is 0N/A * guaranteed by the fact that it is only called indirectly 0N/A * by java.net.URL class. 0N/A * @param u1 a URL object 0N/A * @param u2 a URL object 0N/A * @return true if u1 and u2 refer to the same file 0N/A // Compare the protocols. 0N/A // Compare the files. 0N/A // Compare the ports. 0N/A // Compare the hosts. 0N/A * Get the IP address of our host. An empty host field or a DNS failure 0N/A * will result in a null return. 0N/A * @param u a URL object 0N/A * @return an <code>InetAddress</code> representing the host 0N/A * Compares the host components of two URLs. 0N/A * @param u1 the URL of the first host to compare 0N/A * @param u2 the URL of the second host to compare 0N/A * @return <tt>true</tt> if and only if they 0N/A * are equal, <tt>false</tt> otherwise. 0N/A // if we have internet address for both, compare them 0N/A // else, if both have host names, compare them 0N/A * Converts a <code>URL</code> of a specific protocol to a 0N/A * <code>String</code>. 0N/A * @return a string representation of the <code>URL</code> argument. 0N/A // pre-compute length of StringBuffer 0N/A * Sets the fields of the <code>URL</code> argument to the indicated values. 0N/A * Only classes derived from URLStreamHandler are supposed to be able 0N/A * to call the set method on a URL. 0N/A * @param u the URL to modify. 0N/A * @param protocol the protocol name. 0N/A * @param host the remote host value for the URL. 0N/A * @param port the port on the remote machine. 0N/A * @param authority the authority part for the URL. 0N/A * @param userInfo the userInfo part of the URL. 0N/A * @param path the path component of the URL. 0N/A * @param query the query part for the URL. 0N/A * @param ref the reference. 0N/A * @exception SecurityException if the protocol handler of the URL is 0N/A * different from this one 0N/A * @see java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String) 0N/A // ensure that no one can reset the protocol on a given URL. 0N/A * Sets the fields of the <code>URL</code> argument to the indicated values. 0N/A * Only classes derived from URLStreamHandler are supposed to be able 0N/A * to call the set method on a URL. 0N/A * @param u the URL to modify. 0N/A * @param protocol the protocol name. This value is ignored since 1.2. 0N/A * @param host the remote host value for the URL. 0N/A * @param port the port on the remote machine. 0N/A * @param file the file. 0N/A * @param ref the reference. 0N/A * @exception SecurityException if the protocol handler of the URL is 0N/A * different from this one 0N/A * @deprecated Use setURL(URL, String, String, int, String, String, String, 0N/A * Only old URL handlers call this, so assume that the host 0N/A * field might contain "user:passwd@host". Fix as necessary. 0N/A * Assume file might contain query part. Fix as necessary.