Class UrlUtils

java.lang.Object
icu.easyj.core.util.UrlUtils

public abstract class UrlUtils extends Object
URL工具类
Author:
wangliang181230
  • Constructor Details

    • UrlUtils

      public UrlUtils()
  • Method Details

    • normalizePath

      @NonNull public static String normalizePath(String path)
      标准化路径
      1. "\"替换为"/"
      2. 为URL时,取路径
      3. 连续的'/'和\s,替换为单个'/'
      4. 移除最后一位'/'
      5. 前面补齐’/‘
      Parameters:
      path - 路径
      Returns:
      path 标准化后的路径
    • encode

      public static String encode(String s, Charset charset)
      字符串进行URL编码。
      代码是从 OpenJDK8 URLEncoder.encode(String, String) 中复制过来,并进行了优化: - 1、编码入参也由String直接变成了Charset; - 2、StringBuffer变为StringBuilder
      Parameters:
      s - 字符串
      charset - 字符集
      Returns:
      编码后的字符串
      Throws:
      IllegalArgumentException - s或charset为空时,将抛出该异常
    • encode

      public static String encode(String s)
      字符串进行URL编码,编码方式:UTF-8
      Parameters:
      s - 字符串
      Returns:
      编码后的字符串
    • decode

      public static String decode(String s, Charset charset)
      字符串进行URL解码.
      代码是从 OpenJDK8 URLDecoder.decode(String, String) 中复制过来,并进行了优化: - 1、编码入参也由String直接变成了Charset; - 2、StringBuffer变为StringBuilderc
      Parameters:
      s - 字符串
      charset - 字符集
      Returns:
      解码后的字符串
      Throws:
      IllegalArgumentException - s或charset为空时,将抛出该异常
    • decode

      public static String decode(String s)
      字符串进行URL解码
      Parameters:
      s - 字符串
      Returns:
      解码后的字符串
    • joinQueryString

      @NonNull public static String joinQueryString(@NonNull String urlOrPath, Map<String,String> queryStringMap)
      拼接QueryString参数
      Parameters:
      urlOrPath - 原URL或Path
      queryStringMap - 参数Map(键和值都未encode过)
      Returns:
      拼接好参数后的完整URL或Path