< prev index next >

src/java.base/unix/classes/sun/net/www/protocol/file/Handler.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad


  58          * only forward slashes may be used to represent hierarchy
  59          * separation in a URL but previous releases unfortunately
  60          * performed this "fixup" behavior in the file URL parsing code
  61          * rather than forcing this to be fixed in the caller of the URL
  62          * class where it belongs. Since backslash is an "unwise"
  63          * character that would normally be encoded if literally intended
  64          * as a non-seperator character the damage of veering away from the
  65          * specification is presumably limited.
  66          */
  67         super.parseURL(u, spec.replace(File.separatorChar, '/'), start, limit);
  68     }
  69 
  70     public synchronized URLConnection openConnection(URL u)
  71         throws IOException {
  72         return openConnection(u, null);
  73     }
  74 
  75     public synchronized URLConnection openConnection(URL u, Proxy p)
  76            throws IOException {
  77         String host = u.getHost();
  78         if (host == null || host.equals("") || host.equals("~") ||
  79             host.equalsIgnoreCase("localhost")) {
  80             File file = new File(ParseUtil.decode(u.getPath()));
  81             return createFileURLConnection(u, file);
  82         }
  83 
  84         /* If you reach here, it implies that you have a hostname
  85            so attempt an ftp connection.
  86          */
  87         URLConnection uc;
  88         URL ru;
  89 
  90         try {
  91             ru = new URL("ftp", host, u.getFile() +
  92                              (u.getRef() == null ? "": "#" + u.getRef()));
  93             if (p != null) {
  94                 uc = ru.openConnection(p);
  95             } else {
  96                 uc = ru.openConnection();
  97             }
  98         } catch (IOException e) {




  58          * only forward slashes may be used to represent hierarchy
  59          * separation in a URL but previous releases unfortunately
  60          * performed this "fixup" behavior in the file URL parsing code
  61          * rather than forcing this to be fixed in the caller of the URL
  62          * class where it belongs. Since backslash is an "unwise"
  63          * character that would normally be encoded if literally intended
  64          * as a non-seperator character the damage of veering away from the
  65          * specification is presumably limited.
  66          */
  67         super.parseURL(u, spec.replace(File.separatorChar, '/'), start, limit);
  68     }
  69 
  70     public synchronized URLConnection openConnection(URL u)
  71         throws IOException {
  72         return openConnection(u, null);
  73     }
  74 
  75     public synchronized URLConnection openConnection(URL u, Proxy p)
  76            throws IOException {
  77         String host = u.getHost();
  78         if (host == null || host.isEmpty() || host.equals("~") ||
  79             host.equalsIgnoreCase("localhost")) {
  80             File file = new File(ParseUtil.decode(u.getPath()));
  81             return createFileURLConnection(u, file);
  82         }
  83 
  84         /* If you reach here, it implies that you have a hostname
  85            so attempt an ftp connection.
  86          */
  87         URLConnection uc;
  88         URL ru;
  89 
  90         try {
  91             ru = new URL("ftp", host, u.getFile() +
  92                              (u.getRef() == null ? "": "#" + u.getRef()));
  93             if (p != null) {
  94                 uc = ru.openConnection(p);
  95             } else {
  96                 uc = ru.openConnection();
  97             }
  98         } catch (IOException e) {


< prev index next >