< prev index next >

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

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 110     protected URLConnection createFileURLConnection(URL u, File file)
 111     {
 112         return new FileURLConnection(u, file);
 113     }
 114 
 115     /**
 116      * Compares the host components of two URLs.
 117      * @param u1 the URL of the first host to compare
 118      * @param u2 the URL of the second host to compare
 119      * @return  {@code true} if and only if they
 120      * are equal, {@code false} otherwise.
 121      */
 122     protected boolean hostsEqual(URL u1, URL u2) {
 123         /*
 124          * Special case for file: URLs
 125          * per RFC 1738 no hostname is equivalent to 'localhost'
 126          * i.e. file:///path is equal to file://localhost/path
 127          */
 128         String s1 = u1.getHost();
 129         String s2 = u2.getHost();
 130         if ("localhost".equalsIgnoreCase(s1) && ( s2 == null || "".equals(s2)))
 131             return true;
 132         if ("localhost".equalsIgnoreCase(s2) && ( s1 == null || "".equals(s1)))
 133             return true;
 134         return super.hostsEqual(u1, u2);
 135     }
 136 }


 110     protected URLConnection createFileURLConnection(URL u, File file)
 111     {
 112         return new FileURLConnection(u, file);
 113     }
 114 
 115     /**
 116      * Compares the host components of two URLs.
 117      * @param u1 the URL of the first host to compare
 118      * @param u2 the URL of the second host to compare
 119      * @return  {@code true} if and only if they
 120      * are equal, {@code false} otherwise.
 121      */
 122     protected boolean hostsEqual(URL u1, URL u2) {
 123         /*
 124          * Special case for file: URLs
 125          * per RFC 1738 no hostname is equivalent to 'localhost'
 126          * i.e. file:///path is equal to file://localhost/path
 127          */
 128         String s1 = u1.getHost();
 129         String s2 = u2.getHost();
 130         if ("localhost".equalsIgnoreCase(s1) && (s2 == null || s2.isEmpty()))
 131             return true;
 132         if ("localhost".equalsIgnoreCase(s2) && (s1 == null || s1.isEmpty()))
 133             return true;
 134         return super.hostsEqual(u1, u2);
 135     }
 136 }
< prev index next >