56 |
* This final class represents an Internet Uniform Resource Locator (URL). |
* This final class represents an Internet Uniform Resource Locator (URL). |
57 |
* For details on the syntax of URL's and what they can be used for, |
* For details on the syntax of URL's and what they can be used for, |
58 |
* refer to RFC 1738, available from <a |
* refer to RFC 1738, available from <a |
59 |
* href="http://ds.internic.net/rfcs/rfc1738.txt">http://ds.internic.net/rfcs/rfc1738.txt</a> |
* href="http://ds.internic.net/rfcs/rfc1738.txt"> |
60 |
|
* http://ds.internic.net/rfcs/rfc1738.txt</a> |
61 |
* <p> |
* <p> |
62 |
* There are a great many protocols supported by URL's such as "http", |
* There are a great many protocols supported by URL's such as "http", |
63 |
* "ftp", and "file". This object can handle any arbitrary URL for which |
* "ftp", and "file". This object can handle any arbitrary URL for which |
74 |
* If this property is set, it is assumed to be a "|" separated list of |
* If this property is set, it is assumed to be a "|" separated list of |
75 |
* package names in which to attempt locating protocol handlers. The |
* package names in which to attempt locating protocol handlers. The |
76 |
* protocol handler is searched for by appending the string |
* protocol handler is searched for by appending the string |
77 |
* ".<protocol>.Handler" to each packed in the list until a hander is found. |
* ".<protocol>.Handler" to each packed in the list until a hander is |
78 |
* If a protocol handler is not found in this list of packages, or if the |
* found. If a protocol handler is not found in this list of packages, or if |
79 |
* property does not exist, then the default protocol handler of |
* the property does not exist, then the default protocol handler of |
80 |
* "gnu.java.net.<protocol>.Handler" is tried. If this is |
* "gnu.java.net.<protocol>.Handler" is tried. If this is |
81 |
* unsuccessful, a MalformedURLException is thrown. |
* unsuccessful, a MalformedURLException is thrown. |
82 |
* <p> |
* <p> |
83 |
* All of the constructor methods of URL attempt to load a protocol |
* All of the constructor methods of URL attempt to load a protocol |
311 |
this((URL) null, spec, (URLStreamHandler) null); |
this((URL) null, spec, (URLStreamHandler) null); |
312 |
} |
} |
313 |
|
|
314 |
/* |
/** |
315 |
* This method parses a String representation of a URL within the |
* This method parses a String representation of a URL within the |
316 |
* context of an existing URL. Principally this means that any |
* context of an existing URL. Principally this means that any |
317 |
* fields not present the URL are inheritied from the context URL. |
* fields not present the URL are inheritied from the context URL. |
476 |
/** |
/** |
477 |
* Gets the contents of this URL |
* Gets the contents of this URL |
478 |
* |
* |
479 |
|
* @param classes The allow classes for the content object. |
480 |
|
* |
481 |
|
* @return a context object for this URL. |
482 |
|
* |
483 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
484 |
*/ |
*/ |
485 |
public final Object getContent (Class[] classes) throws IOException |
public final Object getContent (Class[] classes) throws IOException |
492 |
* Returns the file portion of the URL. |
* Returns the file portion of the URL. |
493 |
* Defined as <code>path[?query]</code>. |
* Defined as <code>path[?query]</code>. |
494 |
* Returns the empty string if there is no file portion. |
* Returns the empty string if there is no file portion. |
495 |
|
* |
496 |
|
* @return The filename specified in this URL. |
497 |
*/ |
*/ |
498 |
public String getFile() |
public String getFile() |
499 |
{ |
{ |
504 |
* Returns the path of the URL. This is the part of the file before any '?' |
* Returns the path of the URL. This is the part of the file before any '?' |
505 |
* character. |
* character. |
506 |
* |
* |
507 |
|
* @return The path specified in this URL. |
508 |
|
* |
509 |
* @since 1.3 |
* @since 1.3 |
510 |
*/ |
*/ |
511 |
public String getPath() |
public String getPath() |
516 |
|
|
517 |
/** |
/** |
518 |
* Returns the authority of the URL |
* Returns the authority of the URL |
519 |
|
* |
520 |
|
* @return The authority specified in this URL. |
521 |
* |
* |
522 |
* @since 1.3 |
* @since 1.3 |
523 |
*/ |
*/ |
528 |
|
|
529 |
/** |
/** |
530 |
* Returns the host of the URL |
* Returns the host of the URL |
531 |
|
* |
532 |
|
* @return The host specified in this URL. |
533 |
*/ |
*/ |
534 |
public String getHost() |
public String getHost() |
535 |
{ |
{ |
553 |
/** |
/** |
554 |
* Returns the default port of the URL. If the StreamHandler for the URL |
* Returns the default port of the URL. If the StreamHandler for the URL |
555 |
* protocol does not define a default port it returns -1. |
* protocol does not define a default port it returns -1. |
556 |
|
* |
557 |
|
* @return The default port of the current protocol. |
558 |
*/ |
*/ |
559 |
public int getDefaultPort() |
public int getDefaultPort() |
560 |
{ |
{ |
563 |
|
|
564 |
/** |
/** |
565 |
* Returns the protocol of the URL |
* Returns the protocol of the URL |
566 |
|
* |
567 |
|
* @return The specified protocol. |
568 |
*/ |
*/ |
569 |
public String getProtocol() |
public String getProtocol() |
570 |
{ |
{ |
608 |
|
|
609 |
/** |
/** |
610 |
* Returns a hashcode computed by the URLStreamHandler of this URL |
* Returns a hashcode computed by the URLStreamHandler of this URL |
611 |
|
* |
612 |
|
* @return The hashcode for this URL. |
613 |
*/ |
*/ |
614 |
public int hashCode() |
public int hashCode() |
615 |
{ |
{ |
625 |
* openConnection() method of the protocol handler |
* openConnection() method of the protocol handler |
626 |
* |
* |
627 |
* @return A URLConnection for this URL |
* @return A URLConnection for this URL |
628 |
|
* |
629 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
630 |
*/ |
*/ |
631 |
public URLConnection openConnection() throws IOException |
public URLConnection openConnection() throws IOException |
637 |
* Opens a connection to this URL and returns an InputStream for reading |
* Opens a connection to this URL and returns an InputStream for reading |
638 |
* from that connection |
* from that connection |
639 |
* |
* |
640 |
|
* @return An <code>InputStream</code> for this URL. |
641 |
|
* |
642 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
643 |
*/ |
*/ |
644 |
public final InputStream openStream() throws IOException |
public final InputStream openStream() throws IOException |
695 |
* that only URLStreamHandlers can modify URL fields. URLs are otherwise |
* that only URLStreamHandlers can modify URL fields. URLs are otherwise |
696 |
* constant. |
* constant. |
697 |
* |
* |
698 |
|
* @param protocol The protocol name for this URL. |
699 |
|
* @param host The hostname or IP address for this URL. |
700 |
|
* @param port The port number of this URL. |
701 |
|
* @param authority The authority of this URL. |
702 |
|
* @param userInfo The user and password (if needed) of this URL. |
703 |
|
* @param path The "path" portion of this URL. |
704 |
|
* @param query The query of this URL. |
705 |
|
* @param ref The anchor portion of this URL. |
706 |
|
* |
707 |
* @since 1.3 |
* @since 1.3 |
708 |
*/ |
*/ |
709 |
protected void set(String protocol, String host, int port, |
protected void set(String protocol, String host, int port, |
813 |
// to it, along with the JDK specified default as a last resort. |
// to it, along with the JDK specified default as a last resort. |
814 |
// Except in very unusual environments the JDK specified one shouldn't |
// Except in very unusual environments the JDK specified one shouldn't |
815 |
// ever be needed (or available). |
// ever be needed (or available). |
816 |
String ph_search_path = System.getProperty ("java.protocol.handler.pkgs"); |
String ph_search_path = |
817 |
|
System.getProperty("java.protocol.handler.pkgs"); |
818 |
|
|
819 |
// Tack our default package on at the ends. |
// Tack our default package on at the ends. |
820 |
if (ph_search_path != null) |
if (ph_search_path != null) |
827 |
|
|
828 |
do |
do |
829 |
{ |
{ |
830 |
String clsName = pkgPrefix.nextToken() + "." + protocol + ".Handler"; |
String clsName = (pkgPrefix.nextToken() + "." |
831 |
|
+ protocol + ".Handler"); |
832 |
|
|
833 |
try |
try |
834 |
{ |
{ |
841 |
} |
} |
842 |
catch (Exception e) |
catch (Exception e) |
843 |
{ |
{ |
844 |
// Can't instantiate; handler still null, go on to next element. |
// Can't instantiate; handler still null, |
845 |
|
// go on to next element. |
846 |
} |
} |
847 |
} |
} |
848 |
while ((! (ph instanceof URLStreamHandler)) |
while ((! (ph instanceof URLStreamHandler)) |