Class UrlPath

java.lang.Object
org.miaixz.bus.core.net.url.UrlPath

public class UrlPath extends Object
URL中Path部分的封装
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • UrlPath

      public UrlPath()
  • Method Details

    • of

      public static UrlPath of()
      构建UrlPath
      Returns:
      UrlPath
    • of

      public static UrlPath of(CharSequence pathStr, Charset charset)
      构建UrlPath
      Parameters:
      pathStr - 初始化的路径字符串
      charset - decode用的编码,null表示不做decode
      Returns:
      UrlPath
    • setWithEndTag

      public UrlPath setWithEndTag(boolean withEngTag)
      是否path的末尾加 /
      Parameters:
      withEngTag - 是否path的末尾加 /
      Returns:
      this
    • getSegments

      public List<CharSequence> getSegments()
      获取path的节点列表,如果列表为空,返回ListKit.empty()
      Returns:
      节点列表
    • getSegment

      public CharSequence getSegment(int index)
      获得指定节点
      Parameters:
      index - 节点位置
      Returns:
      节点,无节点或者越界返回null
    • add

      public UrlPath add(CharSequence segment)
      添加到path最后面
      Parameters:
      segment - Path节点
      Returns:
      this
    • addBefore

      public UrlPath addBefore(CharSequence segment)
      添加到path最前面
      Parameters:
      segment - Path节点
      Returns:
      this
    • parse

      public UrlPath parse(CharSequence path, Charset charset)
      解析path
      Parameters:
      path - 路径,类似于aaa/bb/ccc或/aaa/bbb/ccc
      charset - decode编码,null表示不解码
      Returns:
      this
    • build

      public String build(Charset charset)
      构建path,前面带'/'
           path = path-abempty / path-absolute / path-noscheme / path-rootless / path-empty
       
      Parameters:
      charset - encode编码,null表示不做encode
      Returns:
      如果没有任何内容,则返回空字符串""
    • toString

      public String toString()
      Overrides:
      toString in class Object