类 URLUtils

java.lang.Object
com.dtflys.forest.utils.URLUtils

public final class URLUtils extends Object
从以下版本开始:
2017-05-17 16:35
作者:
gongjun[jun.gong@thebeastshop.com]
  • 方法详细资料

    • isURL

      public static boolean isURL(String str)
      判断字符串是否是一个URL
      参数:
      str - 被判断的字符串
      返回:
      true: 是URL, false: 不是URL
    • hasProtocol

      public static boolean hasProtocol(String url)
      URL字符串中是否包含HTTP协议部分
      参数:
      url - 需要被判断的URL字符串
      返回:
      true: 包含HTTP协议, false: 不包含
    • isValidUrl

      public static boolean isValidUrl(String url)
      判断字符串是否为合法的URL
      参数:
      url - 被判断的URL字符串
      返回:
      true: 合法, false: 不合法
    • checkBaseURL

      public static void checkBaseURL(String baseUrl)
    • getValidBaseURL

      public static String getValidBaseURL(String baseUrl)
    • getValidURL

      public static String getValidURL(String baseURL, String uri)
      获取合法的URL字符串

      若 uri 参数不合法,即不包含协议头以及域名/主机名/ip地址部分,则和 baseURL 参数进行合并

      若 uri 参数已经是一个合法的URL字符串,则直接返回

      参数:
      baseURL - 根URL字符串
      uri - URL字符串
      返回:
      合法的URL字符串
    • isNonePort

      public static boolean isNonePort(Integer port)
      判断端口号是否为空
      参数:
      port - 端口号
      返回:
      true: 空端口, false: 不为空
    • isNotNonePort

      public static boolean isNotNonePort(Integer port)
      判断端口号是否不为空
      参数:
      port - 端口号
      返回:
      true: 不为空, false: 空端口
    • allEncode

      public static String allEncode(String content, String encode)
      强制URL Encoding编码
      参数:
      content - 需要编码的原字符串
      encode - 编码字符集
      返回:
      URL Encoding编码结果字符串
    • userInfoEncode

      public static String userInfoEncode(String content, String encode)
      进行用户验证信息的URL Encoding编码
      参数:
      content - 需要编码的原字符串
      encode - 编码字符集
      返回:
      URL Encoding编码结果字符串
    • pathEncode

      public static String pathEncode(String content, String encode)
      进行URI路径的URL Encoding编码
      参数:
      content - 需要编码的原字符串
      encode - 编码字符集
      返回:
      URL Encoding编码结果字符串
    • refEncode

      public static String refEncode(String content, String encode)
      进行URI ref的URL Encoding编码
      参数:
      content - 需要编码的原字符串
      encode - 编码字符集
      返回:
      URL Encoding编码结果字符串
    • queryValueEncode

      public static String queryValueEncode(String content, String encode)
      进行查询参数值部分的URL Encoding编码
      参数:
      content - 需要编码的原字符串
      encode - 编码字符集
      返回:
      URL Encoding编码结果字符串
    • queryValueWithBraceEncode

      public static String queryValueWithBraceEncode(String content, String encode)
      进行 (带不转义大括号的) 查询参数值部分的URL Encoding编码
      参数:
      content - 需要编码的原字符串
      encode - 编码字符集
      返回:
      URL Encoding编码结果字符串
    • encode

      public static String encode(String content, String charset) throws UnsupportedEncodingException
      进行URL Encoding编码

      该方法不会强制进行编码,即某些不需要编码的情况就不会去做URL Encoding

      如一个合法的URL字符串就不会被编码

      参数:
      content - 需要编码的原字符串
      charset - 编码字符集
      返回:
      URL Encoding编码结果字符串
      抛出:
      UnsupportedEncodingException - 编码过程中可能抛出的异常
    • isEncoded

      public static boolean isEncoded(String content)
      判断字符串是否已被URL Encoding编码过
      参数:
      content - 被判断的原字符串
      返回:
      true: 被编码过, false: 未被编码过