Converts a {@code URL} of a specific protocol to a
{@code String}.

@param   u   the URL.
@return  a string representation of the {@code URL} argument.
432973
protected String toExternalForm(URL u) {

        // pre-compute length of StringBuffer
        int len = u.getProtocol().length() + 1;
        if (u.getAuthority() != null && u.getAuthority().length() > 0)
            len += 2 + u.getAuthority().length();
        if (u.getPath() != null) {
            len += u.getPath().length();
        }
        if (u.getQuery() != null) {
            len += 1 + u.getQuery().length();
        }
        if (u.getRef() != null)
            len += 1 + u.getRef().length();

        StringBuilder result = new StringBuilder(len);
        result.append(u.getProtocol());
        result.append(":");
        if (u.getAuthority() != null) {// ANDROID: && u.getAuthority().length() > 0) {
            result.append("//");
            result.append(u.getAuthority());
        }
        String fileAndQuery = u.getFile();
        if (fileAndQuery != null) {
            result.append(fileAndQuery);
        }
        if (u.getRef() != null) {
            result.append("#");
            result.append(u.getRef());
        }
        return result.toString();
    }
330180
public static String encode(String url, Charset charset) {
		if (StrUtil.isEmpty(url)) {
			return url;
		}
		if (null == charset) {
			charset = CharsetUtil.defaultCharset();
		}
		return URLEncoder.DEFAULT.encode(url, charset);
	}
433660
public static String decodeUri(String url)
	{
		int index1 = url.indexOf(sessUrlRewritePrefix);
		int index2 = url.indexOf(qMark);

		String tmp = null;
		if (index2 != -1 && index2 > index1)
		{
			tmp = url.substring(index2);
		}
		if (index1 != -1)
		{
			url = url.substring(0, index1);
			if (tmp != null)
			{
				url = url + tmp;
			}
		}
		return url;
	}
1246963
public com.google.protobuf.ByteString
      getUrlQueryParameterBytes() {
    java.lang.Object ref = urlQueryParameter_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      urlQueryParameter_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
414491
function(url) {
    var protocol;
    if (url.indexOf('http://') !== -1) {
      protocol = http;
    } else if (url.indexOf('https://') !== -1) {
      protocol = https;
    } else {
      throw new Error('unsupported protocol :' + url);
    }

    return protocol;
  }
842093
public static String encodeRedirectURLEL(HttpServletResponse rsp, String url) {
	try {
	    return rsp.encodeRedirectURL(url);
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    return url;
	}
    }
626922
public static String getURLProtocol(String urlString) {
        String protocol = null;
        int firstColon = urlString.indexOf(':');
        if (firstColon >= 0) {
            String specifiedProtocol = urlString.substring(0, firstColon);
            if (FindBugs.knownURLProtocolSet.contains(specifiedProtocol)) {
                protocol = specifiedProtocol;
            }
        }
        return protocol;
    }
1033588
public static String addImpliedHttpIfNecessary(String u) {
        int colon = u.indexOf(':');
        int period = u.indexOf('.');
        if (colon == -1 || (period >= 0) && (period < colon)) {
            // No scheme present; prepend "http://"
            u = "http://" + u;
        }
        return u;
    }
702676
public static String getUriPath(String value) {
        try {
            URL url = new URL(value);
            return url.getPath();
        } catch (MalformedURLException e) {
            return value;
        }
    }
1056341
protected synchronized InetAddress getHostAddress(URL u) {
        if (u.hostAddress != null)
            return (InetAddress) u.hostAddress;

        String host = u.getHost();
        if (host == null || host.equals("")) {
            return null;
        } else {
            try {
                u.hostAddress = InetAddress.getByName(host);
            } catch (UnknownHostException ex) {
                return null;
            } catch (SecurityException se) {
                return null;
            }
        }
        return (InetAddress) u.hostAddress;
    }
757989
public static String getHost(String uriString) {
        try {
            URI uri = new URI(uriString);
            if(uri.getHost()==null) {
                throw new IllegalArgumentException("Invalid URI syntax. Scheme and host must be provided (port number is optional): " + uriString);
            }
            if (uri.getAuthority().startsWith("@") && !uri.getHost().startsWith("@")) {
                return "@" + uri.getHost();
            }
            return uri.getHost();
        }
        catch (URISyntaxException e) {
            try {
                return (new NetworkInterfaceURI(uriString)).getHost();
            }
            catch (IllegalArgumentException ne) {
                throw new IllegalArgumentException(ne.getMessage(), ne);
            }
        }
    }
385428
public static String readURLToString(URL u, String encoding) throws IOException {
		for (int i = 0; i < 30; ++i) {
			URLConnection conn = u.openConnection();

			// handle HTTP URLs
			if (conn instanceof HttpURLConnection) {
				HttpURLConnection hconn = (HttpURLConnection)conn;

				// set timeouts
				hconn.setConnectTimeout(15000);
				hconn.setReadTimeout(15000);

				// handle redirects
				switch (hconn.getResponseCode()) {
				case HttpURLConnection.HTTP_MOVED_PERM:
				case HttpURLConnection.HTTP_MOVED_TEMP:
					String location = hconn.getHeaderField("Location");
					u = new URL(u, location);
					continue;
				}
			}

			return readStreamToString(conn.getInputStream(), encoding);
		}

		throw new IOException("Too many HTTP redirects");
	}
889183
public static String urlEncode(String string) {
		try {
			return URLEncoder.encode(string, "utf-8");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
580516
public static String getUrl(final String url) throws Exception {
        return getUrl(new URL(url), null, null);
    }
1311399
private static String decodeUrl(String url) {
        if (url == null) {
            return null;
        }

        try {
            return URLDecoder.decode(url, CHARSET_UTF8);
        } catch (UnsupportedEncodingException e) {
            return url;
        }
    }
266477
public static String convertHostToPunycode(String uriString) {

        if (uriString.indexOf(":") >= 0) {
            try {
                URI uri = new URI(uriString);
                String authority = uri.getAuthority(); // getHost won't work when we have special characters
                int colonPos = authority.indexOf(':');
                if (colonPos >= 0) {
                    authority = IDN.toASCII(authority.substring(0, colonPos)) + authority.substring(colonPos);
                } else {
                    authority = IDN.toASCII(authority);
                }
                URI uriWithCorrectedHost = new URI(
                    uri.getScheme(),
                    authority,
                    uri.getPath(),
                    uri.getQuery(),
                    uri.getFragment());
                uriString = uriWithCorrectedHost.toASCIIString();
            } catch (URISyntaxException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return uriString;
    }
789494
private static URL uriToURL(final URI uri) {
        if (uri.getScheme().equals("jrt")) {
            // Currently URL cannot handle the "jrt:" scheme, used by system modules.
            throw new IllegalArgumentException("Could not create URL from URI with \"jrt:\" scheme: " + uri);
        }
        try {
            return uri.toURL();
        } catch (final MalformedURLException e) {
            throw new IllegalArgumentException("Could not create URL from URI: " + uri + " -- " + e);
        }
    }