< prev index next >

src/java.base/windows/classes/sun/nio/fs/WindowsUriSupport.java

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


 111 
 112         return toUri(s, path.isUnc(), addSlash);
 113     }
 114 
 115     /**
 116      * Converts given URI to a Path
 117      */
 118     static WindowsPath fromUri(WindowsFileSystem fs, URI uri) {
 119         if (!uri.isAbsolute())
 120             throw new IllegalArgumentException("URI is not absolute");
 121         if (uri.isOpaque())
 122             throw new IllegalArgumentException("URI is not hierarchical");
 123         String scheme = uri.getScheme();
 124         if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
 125             throw new IllegalArgumentException("URI scheme is not \"file\"");
 126         if (uri.getRawFragment() != null)
 127             throw new IllegalArgumentException("URI has a fragment component");
 128         if (uri.getRawQuery() != null)
 129             throw new IllegalArgumentException("URI has a query component");
 130         String path = uri.getPath();
 131         if (path.equals(""))
 132             throw new IllegalArgumentException("URI path component is empty");
 133 
 134         // UNC
 135         String auth = uri.getRawAuthority();
 136         if (auth != null && !auth.equals("")) {
 137             String host = uri.getHost();
 138             if (host == null)
 139                 throw new IllegalArgumentException("URI authority component has undefined host");
 140             if (uri.getUserInfo() != null)
 141                 throw new IllegalArgumentException("URI authority component has user-info");
 142             if (uri.getPort() != -1)
 143                 throw new IllegalArgumentException("URI authority component has port number");
 144 
 145             // IPv6 literal
 146             // 1. drop enclosing brackets
 147             // 2. replace ":" with "-"
 148             // 3. replace "%" with "s" (zone/scopeID delimiter)
 149             // 4. Append .ivp6-literal.net
 150             if (host.startsWith("[")) {
 151                 host = host.substring(1, host.length()-1)
 152                            .replace(':', '-')
 153                            .replace('%', 's');
 154                 host += IPV6_LITERAL_SUFFIX;
 155             }
 156 


 111 
 112         return toUri(s, path.isUnc(), addSlash);
 113     }
 114 
 115     /**
 116      * Converts given URI to a Path
 117      */
 118     static WindowsPath fromUri(WindowsFileSystem fs, URI uri) {
 119         if (!uri.isAbsolute())
 120             throw new IllegalArgumentException("URI is not absolute");
 121         if (uri.isOpaque())
 122             throw new IllegalArgumentException("URI is not hierarchical");
 123         String scheme = uri.getScheme();
 124         if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
 125             throw new IllegalArgumentException("URI scheme is not \"file\"");
 126         if (uri.getRawFragment() != null)
 127             throw new IllegalArgumentException("URI has a fragment component");
 128         if (uri.getRawQuery() != null)
 129             throw new IllegalArgumentException("URI has a query component");
 130         String path = uri.getPath();
 131         if (path.isEmpty())
 132             throw new IllegalArgumentException("URI path component is empty");
 133 
 134         // UNC
 135         String auth = uri.getRawAuthority();
 136         if (auth != null && !auth.isEmpty()) {
 137             String host = uri.getHost();
 138             if (host == null)
 139                 throw new IllegalArgumentException("URI authority component has undefined host");
 140             if (uri.getUserInfo() != null)
 141                 throw new IllegalArgumentException("URI authority component has user-info");
 142             if (uri.getPort() != -1)
 143                 throw new IllegalArgumentException("URI authority component has port number");
 144 
 145             // IPv6 literal
 146             // 1. drop enclosing brackets
 147             // 2. replace ":" with "-"
 148             // 3. replace "%" with "s" (zone/scopeID delimiter)
 149             // 4. Append .ivp6-literal.net
 150             if (host.startsWith("[")) {
 151                 host = host.substring(1, host.length()-1)
 152                            .replace(':', '-')
 153                            .replace('%', 's');
 154                 host += IPV6_LITERAL_SUFFIX;
 155             }
 156 
< prev index next >