private static String preprocessUrlStr(final String str, final boolean encode) {
        if (encode) {
            try {
                return (URLEncoder.encode(str, "UTF-8")
                        .replace("%3A", ":")
                        .replace("%2F", "/")
                        .replace("+", "%20"));
            } catch (UnsupportedEncodingException e) {
                // This should never happen unless there is something
                // fundamentally broken with the running JVM.
                throw new RuntimeException(e);
            }
        }
        return str;
    }
private static String preprocessUrlStr ( final String str , final boolean encode ) { if ( encode ) { try { return ( URLEncoder . encode ( str , "UTF-8" ) . replace ( "%3A" , ":" ) . replace ( "%2F" , "/" ) . replace ( "+" , "%20" ) ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; } } return str ; }
URL encodes the given string.  This allows us to pass special characters
that would otherwise be rejected when building a URI instance.  Because we
need to retain the URI's path structure we subsequently need to replace
percent encoded path delimiters back to their decoded counterparts.

@param str the string to encode
@return the encoded string