< prev index next >

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

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


 128      */
 129     protected URLConnection createFileURLConnection(URL url, File file) {
 130         return new FileURLConnection(url, file);
 131     }
 132 
 133     /**
 134      * Compares the host components of two URLs.
 135      * @param u1 the URL of the first host to compare
 136      * @param u2 the URL of the second host to compare
 137      * @return  {@code true} if and only if they
 138      * are equal, {@code false} otherwise.
 139      */
 140     protected boolean hostsEqual(URL u1, URL u2) {
 141         /*
 142          * Special case for file: URLs
 143          * per RFC 1738 no hostname is equivalent to 'localhost'
 144          * i.e. file:///path is equal to file://localhost/path
 145          */
 146         String s1 = u1.getHost();
 147         String s2 = u2.getHost();
 148         if ("localhost".equalsIgnoreCase(s1) && ( s2 == null || "".equals(s2)))
 149             return true;
 150         if ("localhost".equalsIgnoreCase(s2) && ( s1 == null || "".equals(s1)))
 151             return true;
 152         return super.hostsEqual(u1, u2);
 153     }
 154 }


 128      */
 129     protected URLConnection createFileURLConnection(URL url, File file) {
 130         return new FileURLConnection(url, file);
 131     }
 132 
 133     /**
 134      * Compares the host components of two URLs.
 135      * @param u1 the URL of the first host to compare
 136      * @param u2 the URL of the second host to compare
 137      * @return  {@code true} if and only if they
 138      * are equal, {@code false} otherwise.
 139      */
 140     protected boolean hostsEqual(URL u1, URL u2) {
 141         /*
 142          * Special case for file: URLs
 143          * per RFC 1738 no hostname is equivalent to 'localhost'
 144          * i.e. file:///path is equal to file://localhost/path
 145          */
 146         String s1 = u1.getHost();
 147         String s2 = u2.getHost();
 148         if ("localhost".equalsIgnoreCase(s1) && (s2 == null || s2.isEmpty()))
 149             return true;
 150         if ("localhost".equalsIgnoreCase(s2) && (s1 == null || s1.isEmpty()))
 151             return true;
 152         return super.hostsEqual(u1, u2);
 153     }
 154 }
< prev index next >