2 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
28 import java.io.IOException;
29 import java.io.InputStream;
32 * Class <code>URL</code> represents a Uniform Resource
33 * Locator, a pointer to a "resource" on the World
34 * Wide Web. A resource can be something as simple as a file or a
35 * directory, or it can be a reference to a more complicated object,
36 * such as a query to a database or to a search engine. More
37 * information on the types of URLs and their formats can be found at:
39 * <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
40 * <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
43 * In general, a URL can be broken into several parts. The previous
44 * example of a URL indicates that the protocol to use is
45 * <code>http</code> (HyperText Transfer Protocol) and that the
46 * information resides on a host machine named
47 * <code>www.socs.uts.edu.au</code>. The information on that host
48 * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
49 * meaning of this name on the host machine is both protocol
50 * dependent and host dependent. The information normally resides in
51 * a file, but it could be generated on the fly. This component of
52 * the URL is called the <i>path</i> component.
54 * A URL can optionally specify a "port", which is the
55 * port number to which the TCP connection is made on the remote host
56 * machine. If the port is not specified, the default port for
57 * the protocol is used instead. For example, the default port for
58 * <code>http</code> is <code>80</code>. An alternative port could be
61 * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
64 * The syntax of <code>URL</code> is defined by <a
65 * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC 2396: Uniform
66 * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
67 * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC 2732: Format for
68 * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
69 * also supports scope_ids. The syntax and usage of scope_ids is described
70 * <a href="Inet6Address.html#scoped">here</a>.
72 * A URL may have appended to it a "fragment", also known
73 * as a "ref" or a "reference". The fragment is indicated by the sharp
74 * sign character "#" followed by more characters. For example,
76 * http://java.sun.com/index.html#chapter1
79 * This fragment is not technically part of the URL. Rather, it
80 * indicates that after the specified resource is retrieved, the
81 * application is specifically interested in that part of the
82 * document that has the tag <code>chapter1</code> attached to it. The
83 * meaning of a tag is resource specific.
85 * An application can also specify a "relative URL",
86 * which contains only enough information to reach the resource
87 * relative to another URL. Relative URLs are frequently used within
88 * HTML pages. For example, if the contents of the URL:
90 * http://java.sun.com/index.html
92 * contained within it the relative URL:
96 * it would be a shorthand for:
98 * http://java.sun.com/FAQ.html
101 * The relative URL need not specify all the components of a URL. If
102 * the protocol, host name, or port number is missing, the value is
103 * inherited from the fully specified URL. The file component must be
104 * specified. The optional fragment is not inherited.
106 * The URL class does not itself encode or decode any URL components
107 * according to the escaping mechanism defined in RFC2396. It is the
108 * responsibility of the caller to encode any fields, which need to be
109 * escaped prior to calling URL, and also to decode any escaped fields,
110 * that are returned from URL. Furthermore, because URL has no knowledge
111 * of URL escaping, it does not recognise equivalence between the encoded
112 * or decoded form of the same URL. For example, the two URLs:<br>
113 * <pre> http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
114 * would be considered not equal to each other.
116 * Note, the {@link java.net.URI} class does perform escaping of its
117 * component fields in certain circumstances. The recommended way
118 * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
119 * and to convert between these two classes using {@link #toURI()} and
120 * {@link URI#toURL()}.
122 * The {@link URLEncoder} and {@link URLDecoder} classes can also be
123 * used, but only for HTML form encoding, which is not the same
124 * as the encoding scheme defined in RFC2396.
126 * @author James Gosling
129 public final class URL implements java.io.Serializable {
131 static final long serialVersionUID = -7627629688361524110L;
134 * The property which specifies the package prefix list to be scanned
135 * for protocol handlers. The value of this property (if any) should
136 * be a vertical bar delimited list of package names to search through
137 * for a protocol handler to load. The policy of this class is that
138 * all protocol handlers will be in a class called <protocolname>.Handler,
139 * and each package in the list is examined in turn for a matching
140 * handler. If none are found (or the property is not specified), the
141 * default package prefix, sun.net.www.protocol, is used. The search
142 * proceeds from the first package in the list to the last and stops
143 * when a match is found.
145 private static final String protocolPathProp = "java.protocol.handler.pkgs";
148 * The protocol to use (ftp, http, nntp, ... etc.) .
151 private String protocol;
154 * The host name to connect to.
160 * The protocol port to connect to.
163 private int port = -1;
166 * The specified file name on that host. <code>file</code> is
167 * defined as <code>path[?query]</code>
173 * The query part of this URL.
175 private transient String query;
178 * The authority part of this URL.
181 private String authority;
184 * The path part of this URL.
186 private transient String path;
189 * The userinfo part of this URL.
191 private transient String userInfo;
202 private int hashCode = -1;
205 * Creates a <code>URL</code> object from the specified
206 * <code>protocol</code>, <code>host</code>, <code>port</code>
207 * number, and <code>file</code>.<p>
209 * <code>host</code> can be expressed as a host name or a literal
210 * IP address. If IPv6 literal address is used, it should be
211 * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
213 * href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>;
214 * However, the literal IPv6 address format defined in <a
215 * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC 2373: IP
216 * Version 6 Addressing Architecture</i></a> is also accepted.<p>
218 * Specifying a <code>port</code> number of <code>-1</code>
219 * indicates that the URL should use the default port for the
222 * If this is the first URL object being created with the specified
223 * protocol, a <i>stream protocol handler</i> object, an instance of
224 * class <code>URLStreamHandler</code>, is created for that protocol:
226 * <li>If the application has previously set up an instance of
227 * <code>URLStreamHandlerFactory</code> as the stream handler factory,
228 * then the <code>createURLStreamHandler</code> method of that instance
229 * is called with the protocol string as an argument to create the
230 * stream protocol handler.
231 * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
232 * or if the factory's <code>createURLStreamHandler</code> method
233 * returns <code>null</code>, then the constructor finds the
234 * value of the system property:
236 * java.protocol.handler.pkgs
237 * </pre></blockquote>
238 * If the value of that system property is not <code>null</code>,
239 * it is interpreted as a list of packages separated by a vertical
240 * slash character '<code>|</code>'. The constructor tries to load
243 * <<i>package</i>>.<<i>protocol</i>>.Handler
244 * </pre></blockquote>
245 * where <<i>package</i>> is replaced by the name of the package
246 * and <<i>protocol</i>> is replaced by the name of the protocol.
247 * If this class does not exist, or if the class exists but it is not
248 * a subclass of <code>URLStreamHandler</code>, then the next package
249 * in the list is tried.
250 * <li>If the previous step fails to find a protocol handler, then the
251 * constructor tries to load from a system default package.
253 * <<i>system default package</i>>.<<i>protocol</i>>.Handler
254 * </pre></blockquote>
255 * If this class does not exist, or if the class exists but it is not a
256 * subclass of <code>URLStreamHandler</code>, then a
257 * <code>MalformedURLException</code> is thrown.
260 * <p>Protocol handlers for the following protocols are guaranteed
261 * to exist on the search path :-
263 * http, https, ftp, file, and jar
264 * </pre></blockquote>
265 * Protocol handlers for additional protocols may also be
268 * <p>No validation of the inputs is performed by this constructor.
270 * @param protocol the name of the protocol to use.
271 * @param host the name of the host.
272 * @param port the port number on the host.
273 * @param file the file on the host
274 * @exception MalformedURLException if an unknown protocol is specified.
275 * @see java.lang.System#getProperty(java.lang.String)
276 * @see java.net.URL#setURLStreamHandlerFactory(
277 * java.net.URLStreamHandlerFactory)
278 * @see java.net.URLStreamHandler
279 * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
282 public URL(String protocol, String host, int port, String file)
283 throws MalformedURLException
285 this(protocol, host, port, file, null);
289 * Creates a URL from the specified <code>protocol</code>
290 * name, <code>host</code> name, and <code>file</code> name. The
291 * default port for the specified protocol is used.
293 * This method is equivalent to calling the four-argument
294 * constructor with the arguments being <code>protocol</code>,
295 * <code>host</code>, <code>-1</code>, and <code>file</code>.
297 * No validation of the inputs is performed by this constructor.
299 * @param protocol the name of the protocol to use.
300 * @param host the name of the host.
301 * @param file the file on the host.
302 * @exception MalformedURLException if an unknown protocol is specified.
303 * @see java.net.URL#URL(java.lang.String, java.lang.String,
304 * int, java.lang.String)
306 public URL(String protocol, String host, String file)
307 throws MalformedURLException {
308 this(protocol, host, -1, file);
311 private URL(String protocol, String host, int port, String file,
312 Object handler) throws MalformedURLException {
313 if (handler != null) {
314 throw new SecurityException();
317 protocol = protocol.toLowerCase();
318 this.protocol = protocol;
322 * if host is a literal IPv6 address,
323 * we will make it conform to RFC 2732
325 if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
331 throw new MalformedURLException("Invalid port number :" +
335 authority = (port == -1) ? host : host + ":" + port;
338 Parts parts = new Parts(file);
339 path = parts.getPath();
340 query = parts.getQuery();
343 this.file = path + "?" + query;
347 ref = parts.getRef();
349 // Note: we don't do validation of the URL here. Too risky to change
350 // right now, but worth considering for future reference. -br
351 // if (handler == null &&
352 // (handler = getURLStreamHandler(protocol)) == null) {
353 // throw new MalformedURLException("unknown protocol: " + protocol);
358 * Creates a <code>URL</code> object from the <code>String</code>
361 * This constructor is equivalent to a call to the two-argument
362 * constructor with a <code>null</code> first argument.
364 * @param spec the <code>String</code> to parse as a URL.
365 * @exception MalformedURLException if no protocol is specified, or an
366 * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
367 * @see java.net.URL#URL(java.net.URL, java.lang.String)
369 public URL(String spec) throws MalformedURLException {
374 * Creates a URL by parsing the given spec within a specified context.
376 * The new URL is created from the given context URL and the spec
377 * argument as described in
378 * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
380 * <scheme>://<authority><path>?<query>#<fragment>
381 * </pre></blockquote>
382 * The reference is parsed into the scheme, authority, path, query and
383 * fragment parts. If the path component is empty and the scheme,
384 * authority, and query components are undefined, then the new URL is a
385 * reference to the current document. Otherwise, the fragment and query
386 * parts present in the spec are used in the new URL.
388 * If the scheme component is defined in the given spec and does not match
389 * the scheme of the context, then the new URL is created as an absolute
390 * URL based on the spec alone. Otherwise the scheme component is inherited
391 * from the context URL.
393 * If the authority component is present in the spec then the spec is
394 * treated as absolute and the spec authority and path will replace the
395 * context authority and path. If the authority component is absent in the
396 * spec then the authority of the new URL will be inherited from the
399 * If the spec's path component begins with a slash character
400 * "/" then the
401 * path is treated as absolute and the spec path replaces the context path.
403 * Otherwise, the path is treated as a relative path and is appended to the
404 * context path, as described in RFC2396. Also, in this case,
405 * the path is canonicalized through the removal of directory
406 * changes made by occurences of ".." and ".".
408 * For a more detailed description of URL parsing, refer to RFC2396.
410 * @param context the context in which to parse the specification.
411 * @param spec the <code>String</code> to parse as a URL.
412 * @exception MalformedURLException if no protocol is specified, or an
413 * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
414 * @see java.net.URL#URL(java.lang.String, java.lang.String,
415 * int, java.lang.String)
416 * @see java.net.URLStreamHandler
417 * @see java.net.URLStreamHandler#parseURL(java.net.URL,
418 * java.lang.String, int, int)
420 public URL(URL context, String spec) throws MalformedURLException {
421 this(context, spec, null);
425 * Creates a URL by parsing the given spec with the specified handler
426 * within a specified context. If the handler is null, the parsing
427 * occurs as with the two argument constructor.
429 * @param context the context in which to parse the specification.
430 * @param spec the <code>String</code> to parse as a URL.
431 * @param handler the stream handler for the URL.
432 * @exception MalformedURLException if no protocol is specified, or an
433 * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
434 * @exception SecurityException
435 * if a security manager exists and its
436 * <code>checkPermission</code> method doesn't allow
437 * specifying a stream handler.
438 * @see java.net.URL#URL(java.lang.String, java.lang.String,
439 * int, java.lang.String)
440 * @see java.net.URLStreamHandler
441 * @see java.net.URLStreamHandler#parseURL(java.net.URL,
442 * java.lang.String, int, int)
444 private URL(URL context, String spec, Object handler)
445 throws MalformedURLException
447 String original = spec;
450 String newProtocol = null;
452 boolean isRelative = false;
454 // Check for permission to specify a handler
455 if (handler != null) {
456 throw new SecurityException();
460 limit = spec.length();
461 while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
462 limit--; //eliminate trailing whitespace
464 while ((start < limit) && (spec.charAt(start) <= ' ')) {
465 start++; // eliminate leading whitespace
468 if (spec.regionMatches(true, start, "url:", 0, 4)) {
471 if (start < spec.length() && spec.charAt(start) == '#') {
472 /* we're assuming this is a ref relative to the context URL.
473 * This means protocols cannot start w/ '#', but we must parse
474 * ref URL's like: "hello:there" w/ a ':' in them.
478 for (i = start ; !aRef && (i < limit) &&
479 ((c = spec.charAt(i)) != '/') ; i++) {
482 String s = spec.substring(start, i).toLowerCase();
483 if (isValidProtocol(s)) {
491 // Only use our context if the protocols match.
492 protocol = newProtocol;
493 if ((context != null) && ((newProtocol == null) ||
494 newProtocol.equalsIgnoreCase(context.protocol))) {
495 // inherit the protocol handler from the context
496 // if not specified to the constructor
497 // if (handler == null) {
498 // handler = context.handler;
501 // If the context is a hierarchical URL scheme and the spec
502 // contains a matching scheme then maintain backwards
503 // compatibility and treat it as if the spec didn't contain
504 // the scheme; see 5.2.3 of RFC2396
505 if (context.path != null && context.path.startsWith("/"))
508 if (newProtocol == null) {
509 protocol = context.protocol;
510 authority = context.authority;
511 userInfo = context.userInfo;
520 if (protocol == null) {
521 throw new MalformedURLException("no protocol: "+original);
524 // Get the protocol handler if not specified or the protocol
525 // of the context could not be used
526 // if (handler == null &&
527 // (handler = getURLStreamHandler(protocol)) == null) {
528 // throw new MalformedURLException("unknown protocol: "+protocol);
531 // this.handler = handler;
533 i = spec.indexOf('#', start);
535 ref = spec.substring(i + 1, limit);
540 * Handle special case inheritance of query and fragment
541 * implied by RFC2396 section 5.2.2.
543 if (isRelative && start == limit) {
544 query = context.query;
550 // handler.parseURL(this, spec, start, limit);
552 } catch(MalformedURLException e) {
554 } catch(Exception e) {
555 MalformedURLException exception = new MalformedURLException(e.getMessage());
556 exception.initCause(e);
562 * Returns true if specified string is a valid protocol name.
564 private boolean isValidProtocol(String protocol) {
565 int len = protocol.length();
568 char c = protocol.charAt(0);
569 if (!Character.isLetter(c))
571 for (int i = 1; i < len; i++) {
572 c = protocol.charAt(i);
573 if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
582 * Sets the fields of the URL. This is not a public method so that
583 * only URLStreamHandlers can modify URL fields. URLs are
584 * otherwise constant.
586 * @param protocol the name of the protocol to use
587 * @param host the name of the host
588 @param port the port number on the host
589 * @param file the file on the host
590 * @param ref the internal reference in the URL
592 protected void set(String protocol, String host,
593 int port, String file, String ref) {
594 synchronized (this) {
595 this.protocol = protocol;
597 authority = port == -1 ? host : host + ":" + port;
601 /* This is very important. We must recompute this after the
602 * URL has been changed. */
604 int q = file.lastIndexOf('?');
606 query = file.substring(q+1);
607 path = file.substring(0, q);
614 * Sets the specified 8 fields of the URL. This is not a public method so
615 * that only URLStreamHandlers can modify URL fields. URLs are otherwise
618 * @param protocol the name of the protocol to use
619 * @param host the name of the host
620 * @param port the port number on the host
621 * @param authority the authority part for the url
622 * @param userInfo the username and password
623 * @param path the file on the host
624 * @param ref the internal reference in the URL
625 * @param query the query part of this URL
628 protected void set(String protocol, String host, int port,
629 String authority, String userInfo, String path,
630 String query, String ref) {
631 synchronized (this) {
632 this.protocol = protocol;
635 this.file = query == null ? path : path + "?" + query;
636 this.userInfo = userInfo;
639 /* This is very important. We must recompute this after the
640 * URL has been changed. */
643 this.authority = authority;
648 * Gets the query part of this <code>URL</code>.
650 * @return the query part of this <code>URL</code>,
651 * or <CODE>null</CODE> if one does not exist
654 public String getQuery() {
659 * Gets the path part of this <code>URL</code>.
661 * @return the path part of this <code>URL</code>, or an
662 * empty string if one does not exist
665 public String getPath() {
670 * Gets the userInfo part of this <code>URL</code>.
672 * @return the userInfo part of this <code>URL</code>, or
673 * <CODE>null</CODE> if one does not exist
676 public String getUserInfo() {
681 * Gets the authority part of this <code>URL</code>.
683 * @return the authority part of this <code>URL</code>
686 public String getAuthority() {
691 * Gets the port number of this <code>URL</code>.
693 * @return the port number, or -1 if the port is not set
695 public int getPort() {
700 * Gets the protocol name of this <code>URL</code>.
702 * @return the protocol of this <code>URL</code>.
704 public String getProtocol() {
709 * Gets the host name of this <code>URL</code>, if applicable.
710 * The format of the host conforms to RFC 2732, i.e. for a
711 * literal IPv6 address, this method will return the IPv6 address
712 * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
714 * @return the host name of this <code>URL</code>.
716 public String getHost() {
721 * Gets the file name of this <code>URL</code>.
722 * The returned file portion will be
723 * the same as <CODE>getPath()</CODE>, plus the concatenation of
724 * the value of <CODE>getQuery()</CODE>, if any. If there is
725 * no query portion, this method and <CODE>getPath()</CODE> will
726 * return identical results.
728 * @return the file name of this <code>URL</code>,
729 * or an empty string if one does not exist
731 public String getFile() {
736 * Gets the anchor (also known as the "reference") of this
739 * @return the anchor (also known as the "reference") of this
740 * <code>URL</code>, or <CODE>null</CODE> if one does not exist
742 public String getRef() {
747 * Compares this URL for equality with another object.<p>
749 * If the given object is not a URL then this method immediately returns
750 * <code>false</code>.<p>
752 * Two URL objects are equal if they have the same protocol, reference
753 * equivalent hosts, have the same port number on the host, and the same
754 * file and fragment of the file.<p>
756 * Two hosts are considered equivalent if both host names can be resolved
757 * into the same IP addresses; else if either host name can't be
758 * resolved, the host names must be equal without regard to case; or both
759 * host names equal to null.<p>
761 * Since hosts comparison requires name resolution, this operation is a
762 * blocking operation. <p>
764 * Note: The defined behavior for <code>equals</code> is known to
765 * be inconsistent with virtual hosting in HTTP.
767 * @param obj the URL to compare against.
768 * @return <code>true</code> if the objects are the same;
769 * <code>false</code> otherwise.
771 public boolean equals(Object obj) {
772 if (!(obj instanceof URL))
776 // return handler.equals(this, u2);
781 * Creates an integer suitable for hash table indexing.<p>
783 * The hash code is based upon all the URL components relevant for URL
784 * comparison. As such, this operation is a blocking operation.<p>
786 * @return a hash code for this <code>URL</code>.
788 public synchronized int hashCode() {
792 // hashCode = handler.hashCode(this);
797 * Compares two URLs, excluding the fragment component.<p>
799 * Returns <code>true</code> if this <code>URL</code> and the
800 * <code>other</code> argument are equal without taking the
801 * fragment component into consideration.
803 * @param other the <code>URL</code> to compare against.
804 * @return <code>true</code> if they reference the same remote object;
805 * <code>false</code> otherwise.
807 public boolean sameFile(URL other) {
808 // return handler.sameFile(this, other);
809 throw new UnsupportedOperationException();
813 * Constructs a string representation of this <code>URL</code>. The
814 * string is created by calling the <code>toExternalForm</code>
815 * method of the stream protocol handler for this object.
817 * @return a string representation of this object.
818 * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
820 * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
822 public String toString() {
823 return toExternalForm();
827 * Constructs a string representation of this <code>URL</code>. The
828 * string is created by calling the <code>toExternalForm</code>
829 * method of the stream protocol handler for this object.
831 * @return a string representation of this object.
832 * @see java.net.URL#URL(java.lang.String, java.lang.String,
833 * int, java.lang.String)
834 * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
836 public String toExternalForm() {
837 throw new UnsupportedOperationException();
838 // return handler.toExternalForm(this);
842 * Returns a {@link java.net.URLConnection URLConnection} instance that
843 * represents a connection to the remote object referred to by the
846 * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
847 * created every time when invoking the
848 * {@linkplain java.net.URLStreamHandler#openConnection(URL)
849 * URLStreamHandler.openConnection(URL)} method of the protocol handler for
852 * <P>It should be noted that a URLConnection instance does not establish
853 * the actual network connection on creation. This will happen only when
854 * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
856 * <P>If for the URL's protocol (such as HTTP or JAR), there
857 * exists a public, specialized URLConnection subclass belonging
858 * to one of the following packages or one of their subpackages:
859 * java.lang, java.io, java.util, java.net, the connection
860 * returned will be of that subclass. For example, for HTTP an
861 * HttpURLConnection will be returned, and for JAR a
862 * JarURLConnection will be returned.</P>
864 * @return a {@link java.net.URLConnection URLConnection} linking
866 * @exception IOException if an I/O exception occurs.
867 * @see java.net.URL#URL(java.lang.String, java.lang.String,
868 * int, java.lang.String)
870 // public URLConnection openConnection() throws java.io.IOException {
871 // return handler.openConnection(this);
876 * Opens a connection to this <code>URL</code> and returns an
877 * <code>InputStream</code> for reading from that connection. This
878 * method is a shorthand for:
880 * openConnection().getInputStream()
881 * </pre></blockquote>
883 * @return an input stream for reading from the URL connection.
884 * @exception IOException if an I/O exception occurs.
885 * @see java.net.URL#openConnection()
886 * @see java.net.URLConnection#getInputStream()
888 public final InputStream openStream() throws java.io.IOException {
889 throw new IOException();
890 // return openConnection().getInputStream();
894 * Gets the contents of this URL. This method is a shorthand for:
896 * openConnection().getContent()
897 * </pre></blockquote>
899 * @return the contents of this URL.
900 * @exception IOException if an I/O exception occurs.
901 * @see java.net.URLConnection#getContent()
903 public final Object getContent() throws java.io.IOException {
904 throw new IOException();
905 // return openConnection().getContent();
909 * Gets the contents of this URL. This method is a shorthand for:
911 * openConnection().getContent(Class[])
912 * </pre></blockquote>
914 * @param classes an array of Java types
915 * @return the content object of this URL that is the first match of
916 * the types specified in the classes array.
917 * null if none of the requested types are supported.
918 * @exception IOException if an I/O exception occurs.
919 * @see java.net.URLConnection#getContent(Class[])
922 public final Object getContent(Class[] classes)
923 throws java.io.IOException {
924 throw new IOException();
925 // return openConnection().getContent(classes);
932 String path, query, ref;
935 int ind = file.indexOf('#');
936 ref = ind < 0 ? null: file.substring(ind + 1);
937 file = ind < 0 ? file: file.substring(0, ind);
938 int q = file.lastIndexOf('?');
940 query = file.substring(q+1);
941 path = file.substring(0, q);