httpservices/src/main/java/ucar/httpservices/HTTPUtil.java
static public URI
    parseToURI(final String u)
            throws URISyntaxException
    {
        StringBuilder buf = new StringBuilder();
        int i = 0;
        while(i < u.length()) {
            char c = u.charAt(i);
            if(c == '\\') {
                if(i + 1 == u.length())
                    throw new URISyntaxException(u, "Trailing '\' at end of url");
                buf.append("%5c");
                i++;
                c = u.charAt(i);
                buf.append(String.format("%%%02x", (int) c));
            } else
                buf.append(c);
            i++;
        }
        return new URI(buf.toString());
    }
static public URI
    parseToURI(final String u)
            throws URISyntaxException
    {
        StringBuilder buf = new StringBuilder();
        int i = 0;
        while(i < u.length()) {
            char c = u.charAt(i);
            if(c == '\\') {
                if(i + 1 == u.length())
                    throw new URISyntaxException(u, "Trailing '\' at end of url");
                buf.append("%5c");
                i++;
                c = u.charAt(i);
                buf.append(String.format("%%%02x", (int) c));
            } else
                buf.append(c);
            i++;
        }
        return new URI(buf.toString());
    }
static public URI parseToURI ( final String u ) throws URISyntaxException { StringBuilder buf = new StringBuilder ( ) ; int i = 0 ; while ( i < u . length ( ) ) { char c = u . charAt ( i ) ; if ( c == ' ' ) { if ( i + 1 == u . length ( ) ) throw new URISyntaxException ( u , "Trailing '\' at end of url" ) ; buf . append ( "%5c" ) ; i ++ ; c = u . charAt ( i ) ; buf . append ( String . format ( "%%%02x" , ( int ) c ) ) ; } else buf . append ( c ) ; i ++ ; } return new URI ( buf . toString ( ) ) ; }
Convert a uri string to an instance of java.net.URI.
The critical thing is that this procedure can handle backslash
escaped uris as well as %xx escaped uris.

@param u the uri to convert
@return The URI corresponding to u.
@throws URISyntaxException
Convert a uri string to an instance of java . net . URI . The critical thing is that this procedure can handle backslash escaped uris as well as %xx escaped uris .