Package org.miaixz.bus.http
Class UnoUrl
java.lang.Object
org.miaixz.bus.http.UnoUrl
统一资源定位器(URL),其模式为
http或https。使用这个类来组合和分解Internet地址 这个类有一个现代的API。它避免了惩罚性的检查异常:get()对无效的输入抛出IllegalArgumentException, 或者parse()如果输入是无效的URL,则返回null。您甚至可以明确每个组件是否已经编码- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcanonicalize(String input, String encodeSet, boolean alreadyEncoded, boolean strict, boolean plusIsSpace, boolean asciiOnly, Charset charset) static intdefaultPort(String scheme) Returns 80 ifscheme.equals("http"), 443 ifscheme.equals("https")and -1 otherwise.返回这个URL的片段"abc"forhttp://host/#abc.返回密码,如果没有设置则返回空字符串.该URL编码后用于HTTP资源解析。返回一个已编码的路径段列表["a", "b", "c"]for the URLhttp://host/a/b/c.Returns the query of this URL, encoded for use in HTTP resource resolution.Returns the username, or an empty string if none is set.booleanfragment()返回这个URL的片段"abc"forhttp://host/#abc.static UnoUrlReturns a newHttpUrlrepresentingurl.static UnoUrlstatic UnoUrlinthashCode()host()A regular host name, likeandroid.com.booleanisHttps()newBuilder(String link) Returns a builder for the URL that would be retrieved by followinglinkfrom this URL, or null if the resulting URL is not well-formed.static UnoUrlReturns a newHttpUrlrepresentingurlif it is a well-formed HTTP or HTTPS URL, or null if it isn't.password()返回已解码的密码,如果不存在,则返回空字符串.Returns a list of path segments like["a", "b", "c"]for the URLhttp://host/a/b/c.intpathSize()Returns the number of segments in this URL's path.static StringpercentDecode(String encoded, boolean plusIsSpace) intport()http://host/80http://host:8000/8000https://host/443query()Returns this URL's query, like"abc"forhttp://host/?abc.queryParameter(String name) Returns the first query parameter namednamedecoded using UTF-8, or null if there is no such query parameter.queryParameterName(int index) Returns the name of the query parameter atindex.Returns the distinct query parameter names in this URL, like["a", "b"]forhttp://host/?a=apple&b=banana.queryParameterValue(int index) Returns the value of the query parameter atindex.queryParameterValues(String name) Returns all values for the query parameternameordered by their appearance in this URL.intReturns the number of query parameters in this URL, like 2 forhttp://host/?a=apple&b=banana.redact()scheme()Returns either "http" or "https".toString()uri()Returns this URL as ajava.net.URI.url()Returns this URL as ajava.net.URL.username()返回已解码的用户名,如果不存在,则返回空字符串.
-
Field Details
-
USERNAME_ENCODE_SET
- See Also:
-
PASSWORD_ENCODE_SET
- See Also:
-
PATH_SEGMENT_ENCODE_SET
- See Also:
-
PATH_SEGMENT_ENCODE_SET_URI
- See Also:
-
QUERY_ENCODE_SET
- See Also:
-
QUERY_COMPONENT_REENCODE_SET
- See Also:
-
QUERY_COMPONENT_ENCODE_SET
- See Also:
-
QUERY_COMPONENT_ENCODE_SET_URI
- See Also:
-
FORM_ENCODE_SET
- See Also:
-
FRAGMENT_ENCODE_SET
- See Also:
-
FRAGMENT_ENCODE_SET_URI
- See Also:
-
-
Method Details
-
defaultPort
Returns 80 ifscheme.equals("http"), 443 ifscheme.equals("https")and -1 otherwise. -
parse
Returns a newHttpUrlrepresentingurlif it is a well-formed HTTP or HTTPS URL, or null if it isn't. -
get
Returns a newHttpUrlrepresentingurl.- Throws:
IllegalArgumentException- Ifurlis not a well-formed HTTP or HTTPS URL.
-
get
-
get
-
percentDecode
-
canonicalize
-
url
Returns this URL as ajava.net.URL. -
uri
Returns this URL as ajava.net.URI. BecauseURIis more strict than this class, the returned URI may be semantically different from this URL:- Characters forbidden by URI like
[and|will be escaped. - Invalid percent-encoded sequences like
%xxwill be encoded like%25xx. - Whitespace and control characters in the fragment will be stripped.
These differences may have a significant consequence when the URI is interpreted by a webserver. For this reason the URI class and this method should be avoided.
- Characters forbidden by URI like
-
scheme
Returns either "http" or "https". -
isHttps
public boolean isHttps() -
encodedUsername
Returns the username, or an empty string if none is set. -
username
返回已解码的用户名,如果不存在,则返回空字符串.http://host/""http://username@host/"username"http://username:password@host/"username"http://a%20b:c%20d@host/"a b"
- Returns:
- 用户信息
-
encodedPassword
返回密码,如果没有设置则返回空字符串.http://host/""http://username@host/""http://username:password@host/"password"http://a%20b:c%20d@host/"c%20d"
- Returns:
- 返回密码
-
password
返回已解码的密码,如果不存在,则返回空字符串.http://host/""http://username@host/""http://username:password@host/"password"http://a%20b:c%20d@host/"c d"
- Returns:
- 返回已解码的密码
-
host
- A regular host name, like
android.com. - An IPv4 address, like
127.0.0.1. - An IPv6 address, like
::1. - An encoded IDN, like
xn--n3h.net.
http://android.com/"android.com"http://127.0.0.1/"127.0.0.1"http://[::1]/"::1"http://xn--n3h.net/"xn--n3h.net"
- Returns:
- 主机host
- A regular host name, like
-
port
public int port()http://host/80http://host:8000/8000https://host/443
- Returns:
- 端口
-
pathSize
public int pathSize()Returns the number of segments in this URL's path. This is also the number of slashes in the URL's path, like 3 inhttp://host/a/b/c. This is always at least 1.http://host/1http://host/a/b/c3http://host/a/b/c/4
- Returns:
- the size
-
encodedPath
该URL编码后用于HTTP资源解析。返回的路径将以/开始http://host//http://host/a/b/c"/a/b/c"http://host/a/b%20c/d"/a/b%20c/d"
- Returns:
- URL的完整路径
-
encodedPathSegments
返回一个已编码的路径段列表["a", "b", "c"]for the URLhttp://host/a/b/c. 这个列表从不为空,尽管它可能包含一个空字符串.http://host/[""]http://host/a/b/c["a", "b", "c"]http://host/a/b%20c/d["a", "b%20c", "d"]
- Returns:
- 路径段列表
-
pathSegments
Returns a list of path segments like["a", "b", "c"]for the URLhttp://host/a/b/c. This list is never empty though it may contain a single empty string.http://host/[""]http://host/a/b/c"["a", "b", "c"]http://host/a/b%20c/d"["a", "b c", "d"]
- Returns:
- the string
-
encodedQuery
Returns the query of this URL, encoded for use in HTTP resource resolution. The returned string may be null (for URLs with no query), empty (for URLs with an empty query) or non-empty (all other URLs).http://host/nullhttp://host/?""http://host/?a=apple&k=key+lime"a=apple&k=key+lime"http://host/?a=apple&a=apricot"a=apple&a=apricot"http://host/?a=apple&b"a=apple&b"
- Returns:
- the string
-
query
Returns this URL's query, like"abc"forhttp://host/?abc. Most callers should preferqueryParameterName(int)andqueryParameterValue(int)because these methods offer direct access to individual query parameters.http://host/nullhttp://host/?""http://host/?a=apple&k=key+lime"a=apple&k=key lime"http://host/?a=apple&a=apricot"a=apple&a=apricot"http://host/?a=apple&b"a=apple&b"
- Returns:
- the string
-
querySize
public int querySize()Returns the number of query parameters in this URL, like 2 forhttp://host/?a=apple&b=banana. If this URL has no query this returns 0. Otherwise it returns one more than the number of"&"separators in the query.http://host/0http://host/?1http://host/?a=apple&k=key+lime2http://host/?a=apple&a=apricot2http://host/?a=apple&b2
- Returns:
- the int
-
queryParameter
Returns the first query parameter namednamedecoded using UTF-8, or null if there is no such query parameter.http://host/nullhttp://host/?nullhttp://host/?a=apple&k=key+lime"apple"http://host/?a=apple&a=apricot"apple"http://host/?a=apple&b"apple"
- Parameters:
name- 名称- Returns:
- the string
-
queryParameterNames
Returns the distinct query parameter names in this URL, like["a", "b"]forhttp://host/?a=apple&b=banana. If this URL has no query this returns the empty set.http://host/[]http://host/?[""]http://host/?a=apple&k=key+lime["a", "k"]http://host/?a=apple&a=apricot["a"]http://host/?a=apple&b["a", "b"]
- Returns:
- the set
-
queryParameterValues
Returns all values for the query parameternameordered by their appearance in this URL. For example this returns["banana"]forqueryParameterValue("b")onhttp://host/?a=apple&b=banana.http://host/[][]http://host/?[][]http://host/?a=apple&k=key+lime["apple"][]http://host/?a=apple&a=apricot["apple", "apricot"][]http://host/?a=apple&b["apple"][null]
- Parameters:
name- 名称- Returns:
- the list
-
queryParameterName
Returns the name of the query parameter atindex. For example this returns"a"forqueryParameterName(0)onhttp://host/?a=apple&b=banana. This throws ifindexis not less than the query size.http://host/exceptionexceptionhttp://host/?""exceptionhttp://host/?a=apple&k=key+lime"a""k"http://host/?a=apple&a=apricot"a""a"http://host/?a=apple&b"a""b"
- Parameters:
index- 索引- Returns:
- the string
-
queryParameterValue
Returns the value of the query parameter atindex. For example this returns"apple"forqueryParameterName(0)onhttp://host/?a=apple&b=banana. This throws ifindexis not less than the query size.http://host/exceptionexceptionhttp://host/?nullexceptionhttp://host/?a=apple&k=key+lime"apple""key lime"http://host/?a=apple&a=apricot"apple""apricot"http://host/?a=apple&b"apple"null
- Parameters:
index- 索引- Returns:
- the string
-
encodedFragment
返回这个URL的片段"abc"forhttp://host/#abc. 如果URL没有片段,则返回nullhttp://host/nullhttp://host/#""http://host/#abc"abc"http://host/#abc|def"abc|def"
- Returns:
- the string
-
fragment
返回这个URL的片段"abc"forhttp://host/#abc. 如果URL没有片段,则返回nullhttp://host/nullhttp://host/#""http://host/#abc"abc"http://host/#abc|def"abc|def"
- Returns:
- the string
-
redact
-
resolve
-
newBuilder
-
newBuilder
Returns a builder for the URL that would be retrieved by followinglinkfrom this URL, or null if the resulting URL is not well-formed. -
equals
-
hashCode
public int hashCode() -
toString
-