/[classpath]/classpath/java/net/URL.java
ViewVC logotype

Diff of /classpath/java/net/URL.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by mkoch, Thu Jun 19 09:59:13 2003 UTC revision 1.15 by mkoch, Fri Jun 27 22:13:48 2003 UTC
# Line 160  public final class URL implements Serial Line 160  public final class URL implements Serial
160    /**    /**
161     * The protocol handler in use for this URL     * The protocol handler in use for this URL
162     */     */
163    transient URLStreamHandler handler;    transient URLStreamHandler ph;
164    
165    /**    /**
166     * This a table where we cache protocol handlers to avoid the overhead     * This a table where we cache protocol handlers to avoid the overhead
# Line 259  public final class URL implements Serial Line 259  public final class URL implements Serial
259     * @param port The port number to use, or -1 to use the protocol's default     * @param port The port number to use, or -1 to use the protocol's default
260     * port     * port
261     * @param file The "file" portion of the URL.     * @param file The "file" portion of the URL.
262     * @param handler The protocol handler to use with this URL.     * @param ph The protocol handler to use with this URL.
263     *     *
264     * @exception MalformedURLException If no protocol handler can be loaded     * @exception MalformedURLException If no protocol handler can be loaded
265     * for the specified protocol.     * for the specified protocol.
# Line 268  public final class URL implements Serial Line 268  public final class URL implements Serial
268     *     *
269     * @since 1.2     * @since 1.2
270     */     */
271    public URL(String protocol, String host, int port, String file,    public URL (String protocol, String host, int port, String file,
272      URLStreamHandler handler) throws MalformedURLException                URLStreamHandler ph)
273        throws MalformedURLException
274    {    {
275      if (protocol == null)      if (protocol == null)
276        throw new MalformedURLException("null protocol");        throw new MalformedURLException("null protocol");
277      this.protocol = protocol.toLowerCase();      this.protocol = protocol.toLowerCase();
278    
279      if (handler != null)      if (ph != null)
280        {        {
281          SecurityManager s = System.getSecurityManager();          SecurityManager s = System.getSecurityManager();
282          if (s != null)          if (s != null)
283            s.checkPermission (new NetPermission ("specifyStreamHandler"));            s.checkPermission (new NetPermission ("specifyStreamHandler"));
284    
285          this.handler = handler;          this.ph = ph;
286        }        }
287      else      else
288        this.handler = getURLStreamHandler(protocol);        this.ph = getURLStreamHandler(protocol);
289    
290      if (this.handler == null)      if (this.ph == null)
291        throw new MalformedURLException (        throw new MalformedURLException (
292                        "Protocol handler not found: " + protocol);                        "Protocol handler not found: " + protocol);
293    
# Line 365  public final class URL implements Serial Line 366  public final class URL implements Serial
366     *     *
367     * @param context The context in which to parse the specification     * @param context The context in which to parse the specification
368     * @param spec The string to parse as an URL     * @param spec The string to parse as an URL
369     * @param handler The stream handler for the URL     * @param ph The stream handler for the URL
370     *     *
371     * @exception MalformedURLException If a protocol handler cannot be found     * @exception MalformedURLException If a protocol handler cannot be found
372     * or the URL cannot be parsed     * or the URL cannot be parsed
# Line 374  public final class URL implements Serial Line 375  public final class URL implements Serial
375     *     *
376     * @since 1.2     * @since 1.2
377     */     */
378    public URL(URL context, String spec, URLStreamHandler handler)    public URL(URL context, String spec, URLStreamHandler ph)
379      throws MalformedURLException      throws MalformedURLException
380    {    {
381      /* A protocol is defined by the doc as the substring before a ':'      /* A protocol is defined by the doc as the substring before a ':'
# Line 427  public final class URL implements Serial Line 428  public final class URL implements Serial
428        throw new        throw new
429            MalformedURLException("Absolute URL required with null context");            MalformedURLException("Absolute URL required with null context");
430    
431      if (handler != null)      if (ph != null)
432        {        {
433          SecurityManager s = System.getSecurityManager ();          SecurityManager s = System.getSecurityManager ();
434          if (s != null)          if (s != null)
435            s.checkPermission (new NetPermission ("specifyStreamHandler"));            s.checkPermission (new NetPermission ("specifyStreamHandler"));
436    
437          this.handler = handler;          this.ph = ph;
438        }        }
439      else      else
440        this.handler = getURLStreamHandler(protocol);        this.ph = getURLStreamHandler(protocol);
441    
442      if (this.handler == null)      if (this.ph == null)
443        throw new MalformedURLException("Protocol handler not found: "        throw new MalformedURLException("Protocol handler not found: "
444                                        + protocol);                                        + protocol);
445    
# Line 446  public final class URL implements Serial Line 447  public final class URL implements Serial
447      // is to be excluded by passing the 'limit' as the indexOf the '#'      // is to be excluded by passing the 'limit' as the indexOf the '#'
448      // if one exists, otherwise pass the end of the string.      // if one exists, otherwise pass the end of the string.
449      int hashAt = spec.indexOf('#', colon + 1);      int hashAt = spec.indexOf('#', colon + 1);
450      this.handler.parseURL(this, spec, colon + 1,      this.ph.parseURL(this, spec, colon + 1,
451                            hashAt < 0 ? spec.length() : hashAt);                            hashAt < 0 ? spec.length() : hashAt);
452      if (hashAt >= 0)      if (hashAt >= 0)
453        ref = spec.substring(hashAt + 1);        ref = spec.substring(hashAt + 1);
# Line 469  public final class URL implements Serial Line 470  public final class URL implements Serial
470      if (obj == null || ! (obj instanceof URL))      if (obj == null || ! (obj instanceof URL))
471        return false;        return false;
472    
473      return handler.equals (this, (URL) obj);      return ph.equals (this, (URL) obj);
474    }    }
475    
476    /**    /**
# Line 558  public final class URL implements Serial Line 559  public final class URL implements Serial
559     */     */
560    public int getDefaultPort()    public int getDefaultPort()
561    {    {
562      return handler.getDefaultPort();      return ph.getDefaultPort();
563    }    }
564    
565    /**    /**
# Line 612  public final class URL implements Serial Line 613  public final class URL implements Serial
613      if (hashCode != 0)      if (hashCode != 0)
614        return hashCode;          // Use cached value if available.        return hashCode;          // Use cached value if available.
615      else      else
616        return handler.hashCode (this);        return ph.hashCode (this);
617    }    }
618    
619    /**    /**
# Line 625  public final class URL implements Serial Line 626  public final class URL implements Serial
626     */     */
627    public URLConnection openConnection() throws IOException    public URLConnection openConnection() throws IOException
628    {    {
629      return handler.openConnection(this);      return ph.openConnection(this);
630    }    }
631    
632    /**    /**
# Line 651  public final class URL implements Serial Line 652  public final class URL implements Serial
652     */     */
653    public boolean sameFile(URL other)    public boolean sameFile(URL other)
654    {    {
655      return handler.sameFile(this, other);      return ph.sameFile(this, other);
656    }    }
657    
658    /**    /**
# Line 673  public final class URL implements Serial Line 674  public final class URL implements Serial
674      // invalid protocol.  It will cause the handler to be set to null      // invalid protocol.  It will cause the handler to be set to null
675      // thus overriding a valid handler.  Callers of this method should      // thus overriding a valid handler.  Callers of this method should
676      // be aware of this.      // be aware of this.
677      this.handler = getURLStreamHandler(protocol);      this.ph = getURLStreamHandler(protocol);
678      this.protocol = protocol.toLowerCase();      this.protocol = protocol.toLowerCase();
679      this.authority = null;      this.authority = null;
680      this.port = port;      this.port = port;
# Line 698  public final class URL implements Serial Line 699  public final class URL implements Serial
699      // invalid protocol.  It will cause the handler to be set to null      // invalid protocol.  It will cause the handler to be set to null
700      // thus overriding a valid handler.  Callers of this method should      // thus overriding a valid handler.  Callers of this method should
701      // be aware of this.      // be aware of this.
702      this.handler = getURLStreamHandler(protocol);      this.ph = getURLStreamHandler(protocol);
703      this.protocol = protocol.toLowerCase();      this.protocol = protocol.toLowerCase();
704      if (userInfo == null)      if (userInfo == null)
705        this.host = host;        this.host = host;
# Line 747  public final class URL implements Serial Line 748  public final class URL implements Serial
748    public String toExternalForm()    public String toExternalForm()
749    {    {
750      // Identical to toString().      // Identical to toString().
751      return handler.toExternalForm(this);      return ph.toExternalForm(this);
752    }    }
753    
754    /**    /**
# Line 760  public final class URL implements Serial Line 761  public final class URL implements Serial
761    public String toString()    public String toString()
762    {    {
763      // Identical to toExternalForm().      // Identical to toExternalForm().
764      return handler.toExternalForm(this);      return ph.toExternalForm(this);
765    }    }
766    
767    /**    /**
768     * This internal method is used in two different constructors to load     * This internal method is used in two different constructors to load
769     * a protocol handler for this URL.     * a protocol handler for this URL.
770     *     *
771     * @param The protocol to load a handler for     * @param protocol The protocol to load a handler for
772     *     *
773     * @return A URLStreamHandler for this protocol, or null when not found.     * @return A URLStreamHandler for this protocol, or null when not found.
774     */     */
# Line 835  public final class URL implements Serial Line 836  public final class URL implements Serial
836      throws IOException, ClassNotFoundException      throws IOException, ClassNotFoundException
837    {    {
838      ois.defaultReadObject();      ois.defaultReadObject();
839      this.handler = getURLStreamHandler(protocol);      this.ph = getURLStreamHandler(protocol);
840      if (this.handler == null)      if (this.ph == null)
841        throw new IOException("Handler for protocol " + protocol + " not found");        throw new IOException("Handler for protocol " + protocol + " not found");
842    }    }
843    

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26