将URL转换成String

@param url {@link URL}

@return {@link String}
17635
public static String urlToString(URL url) {
        return Checker.isNull(url) ? "" : url.toString().replaceAll("file:" + (Checker.isWindows() ? "/?" : ""), "");
    }
817692
public URL getURL(final String pUrl) {

        try {
            return new URL(pUrl);
        } catch (final MalformedURLException e) {
            throw new ConversionException("Cannot parse URL from string " + pUrl, e);
        }
    }
696739
public static Map<String, String> parseUrl(String url) {
        Map<String, String> result = new HashMap<>(8);
        result.put(PROTOCOL_KEY, ValueConsts.EMPTY_STRING);
        result.put(HOST_KEY, ValueConsts.EMPTY_STRING);
        result.put(PATH_KEY, ValueConsts.EMPTY_STRING);
        if (Checker.isNotEmpty(url)) {
            String[] pros;
            final String protocolSplit = "://";
            if (url.contains(protocolSplit)) {
                pros = url.split(protocolSplit);
            } else {
                pros = new String[]{"", url};
            }
            // 设置主机、协议、路径
            result.put(PROTOCOL_KEY, pros[0]);
            if (pros.length < ValueConsts.TWO_INT) {
                pros = new String[]{pros[0], ValueConsts.EMPTY_STRING};
            }
            if (pros[1].contains(ValueConsts.SPLASH_STRING)) {
                int lastIndex = pros[1].lastIndexOf(ValueConsts.SPLASH_STRING);
                if (pros[1].startsWith(ValueConsts.SPLASH_STRING)) {
                    // 文件协议
                    result.put(PATH_KEY, pros[1].substring(1));
                } else if (pros[1].contains(ValueConsts.SPLASH_STRING)) {
                    int index = pros[1].indexOf("/");
                    // 设置主机
                    result.put(HOST_KEY, pros[1].substring(0, index));
                    // 设置参数
                    if (pros[1].contains(ValueConsts.QUESTION_MARK)) {
                        lastIndex = pros[1].indexOf(ValueConsts.QUESTION_MARK);
                        String[] params = pros[1].split("\\?")[1].split("&");
                        for (String param : params) {
                            String[] kv = param.split("=");
                            result.put(kv[0], kv[1]);
                        }
                    }
                    // 设置路径
                    if (lastIndex > index) {
                        String path = pros[1].substring(index + 1, lastIndex);
                        path = path.endsWith(ValueConsts.SPLASH_STRING) ? path.substring(0, path.length() - 1) : path;
                        result.put(PATH_KEY, path);
                    }
                } else {
                    result.put(HOST_KEY, pros[1]);
                }
            } else {
                result.put(HOST_KEY, pros[1]);
            }
        }
        return result;
    }
906003
protected URL extractURL(Object url)
    throws IOException {
    if (!(url instanceof String)) {
      return null;
    }
    return (null == url || "".equals(url)) ? null : new URL( (String) url);
  }
154854
public static String getValueFromUrl(String url, String preText, int length) {
		String urlContents = getUrlContents(url);
		int indexOf = urlContents.indexOf(preText);
		if (indexOf != -1) {
			indexOf += preText.length();
			String substring = urlContents.substring(indexOf, indexOf + length);
			return substring;
		}
		return null;
	}
934072
static void openURL(String url) {
    try {
      openURL(new URL(url));
    } catch (MalformedURLException ex) {
      Tools.showError(ex);
    }
  }
609024
@SuppressWarnings("checkstyle:abbreviationaswordinname")
    public URL constructURL() {
        String params = encodeQueryParams();
        String stringUri = url;

        if (params.length() > 0) {
            stringUri += "?" + params;
        }

        try {
            URI uri = new URI(stringUri);
            return uri.toURL();
        } catch (final URISyntaxException e) {
            throw new ApiException("Bad URI: " + stringUri, e);
        } catch (final MalformedURLException e) {
            throw new ApiException("Bad URL: " + stringUri, e);
        }
    }
861350
public static ExpectedCondition<Boolean> urlToBe(final String url) {
    return new ExpectedCondition<Boolean>() {
      private String currentUrl = "";

      @Override
      public Boolean apply(WebDriver driver) {
        currentUrl = driver.getCurrentUrl();
        return currentUrl != null && currentUrl.equals(url);
      }

      @Override
      public String toString() {
        return String.format("url to be \"%s\". Current url: \"%s\"", url, currentUrl);
      }
    };
  }
1307538
public String urlDecode(String s) {
        if (s == null || s.isEmpty()) {
            return s;
        }
        return URL.decodeQueryString(s);
    }
395498
@Override
    public String encodeRedirectURL(String url) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "encodeRedirectURL: " + url);
        }
        return encodeURL(url);
    }
273458
public static String urlWithForm(String url, Map<String, Object> form, Charset charset, boolean isEncodeParams) {
		if (isEncodeParams && StrUtil.contains(url, '?')) {
			// 在需要编码的情况下，如果url中已经有部分参数，则编码之
			url = encodeParams(url, charset);
		}

		// url和参数是分别编码的
		return urlWithForm(url, toParams(form, charset), charset, false);
	}
1219425
public String applyOnURL(String url) {
        if (StringUtils.isBlank(url)) {
            return url;
        }
        return StringUtils.substringBefore(url, "?") + toString();
    }
440993
private static URL fixURL(URL jarURL)
    {
        String jarURLString = jarURL.toExternalForm();
        if (StringUtils.contains(jarURLString, ' ')) {
            jarURLString = jarURLString.replace(" ", "%20");

            try {
                return new URL(jarURLString);
            } catch (MalformedURLException e) {
                // TODO: Log something ?
            }
        }

        return jarURL;
    }
911993
public static boolean validateUrl(String url) {
        String[] schemes = {"https"};
        UrlValidator urlValidator = new UrlValidator(schemes);
        return urlValidator.isValid(url);
    }
1286856
public static String urlFormDecode(final String s)
        {
        if (StringUtils.isBlank(s))
            {
            LOG.warn("Could not encode blank string");
            throw new IllegalArgumentException("Blank string");
            }
        try
            {
            return URLDecoder.decode(s, "UTF-8");
            }
        catch (final UnsupportedEncodingException e)
            {
            LOG.error ("Could not encode: " + s, e);            
            return s;
            }
        }
1108364
public void setUrl( CharSequence url) {
		if ( url != null) format.getHeader().createEntry( URL, url);
	}
297203
public static URI urlToURI(URL url) {
    try {
      return url.toURI();
    }
    catch (URISyntaxException e) {
      throw LOG.cannotConvertUrlToUri(url, e);
    }
  }