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

Diff of /classpath/java/net/URLStreamHandler.java

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

revision 1.19 by mkoch, Fri Sep 19 06:19:42 2003 UTC revision 1.20 by mark, Thu Nov 13 22:55:40 2003 UTC
# Line 129  public abstract class URLStreamHandler Line 129  public abstract class URLStreamHandler
129            
130      if (spec.regionMatches (start, "//", 0, 2))      if (spec.regionMatches (start, "//", 0, 2))
131        {        {
132            String genuineHost;
133          int hostEnd;          int hostEnd;
134          int colon;          int colon, at_host;
135    
136          start += 2;          start += 2;
137          int slash = spec.indexOf('/', start);          int slash = spec.indexOf ('/', start);
138          if (slash >= 0)          if (slash >= 0)
139            hostEnd = slash;            hostEnd = slash;
140          else          else
# Line 141  public abstract class URLStreamHandler Line 142  public abstract class URLStreamHandler
142    
143          host = spec.substring (start, hostEnd);          host = spec.substring (start, hostEnd);
144                    
145            // We first need a genuine host name (with userinfo).
146            // So we check for '@': if it's present check the port in the
147            // section after '@' in the other case check it in the full string.
148            // P.S.: We don't care having '@' at the beginning of the string.
149            if ((at_host = host.indexOf ('@')) >= 0)
150              genuineHost = host.substring (at_host);
151            else
152              genuineHost = host;
153    
154          // Look for optional port number.  It is valid for the non-port          // Look for optional port number.  It is valid for the non-port
155          // part of the host name to be null (e.g. a URL "http://:80").          // part of the host name to be null (e.g. a URL "http://:80").
156          // TBD: JDK 1.2 in this case sets host to null rather than "";          // TBD: JDK 1.2 in this case sets host to null rather than "";
157          // this is undocumented and likely an unintended side effect in 1.2          // this is undocumented and likely an unintended side effect in 1.2
158          // so we'll be simple here and stick with "". Note that          // so we'll be simple here and stick with "". Note that
159          // "http://" or "http:///" produce a "" host in JDK 1.2.          // "http://" or "http:///" produce a "" host in JDK 1.2.
160          if ((colon = host.indexOf(':')) >= 0)          if ((colon = genuineHost.indexOf (':')) >= 0)
161            {            {
162              try              try
163                {                {
164                  port = Integer.parseInt(host.substring(colon + 1));                  port = Integer.parseInt (genuineHost.substring (colon + 1));
165                }                }
166              catch (NumberFormatException e)              catch (NumberFormatException e)
167                {                {
168                  ; // Ignore invalid port values; port is already set to u's                  ; // Ignore invalid port values; port is already set to u's
169                    // port.                    // port.
170                }                }
171              host = host.substring(0, colon);              // Now we must cut the port number in the original string.
172                if (at_host >= 0)
173                  host = host.substring (0, at_host + colon);
174                else
175                  host = host.substring (0, colon);
176            }            }
177          file = null;          file = null;
178          start = hostEnd;          start = hostEnd;
# Line 451  public abstract class URLStreamHandler Line 465  public abstract class URLStreamHandler
465     */     */
466    protected String toExternalForm(URL u)    protected String toExternalForm(URL u)
467    {    {
468      String protocol, host, file, ref;      String protocol, host, file, ref, user;
469      int port;      int port;
470    
471      protocol = u.getProtocol();      protocol = u.getProtocol();
# Line 465  public abstract class URLStreamHandler Line 479  public abstract class URLStreamHandler
479      port = u.getPort();      port = u.getPort();
480      file = u.getFile();      file = u.getFile();
481      ref = u.getRef();      ref = u.getRef();
482        user = u.getUserInfo();
483    
484      // Guess a reasonable size for the string buffer so we have to resize      // Guess a reasonable size for the string buffer so we have to resize
485      // at most once.      // at most once.
# Line 478  public abstract class URLStreamHandler Line 493  public abstract class URLStreamHandler
493        }        }
494    
495      if (host.length() != 0)      if (host.length() != 0)
496        sb.append("//").append(host);        {
497            sb.append("//");
498            if (user != null && !"".equals(user))
499              sb.append(user).append('@');
500            sb.append(host);
501          }
502    
503      // Note that this produces different results from JDK 1.2 as JDK 1.2      // Note that this produces different results from JDK 1.2 as JDK 1.2
504      // ignores a non-default port if host is null or "".  That is inconsistent      // ignores a non-default port if host is null or "".  That is inconsistent

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

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