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