Package org.aoju.bus.core.toolkit
Class UriKit
java.lang.Object
org.aoju.bus.core.toolkit.UriKit
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classURL中Path部分的封装static classURL中查询字符串部分的封装,类似于:static enum枚举,用于标识每个URI组件允许的字符. -
Constructor Summary
ConstructorsConstructorDescriptionUriKit()构造UriKit(String scheme, String host, int port, UriKit.Path path, UriKit.Query query, String fragment, Charset charset) 构造 -
Method Summary
Modifier and TypeMethodDescription增加路径节点添加查询项,支持重复键appendPath(CharSequence segment) 追加path节点build()创建URL字符串static StringcomplateUrl(String baseUrl, String relativePath) 补全相对路径static String解码URL 将%开头的16进制表示的内容解码。static String解码给定的URI编码组件.static String解码给定的URI编码组件.static String将Map形式的Form表单数据转换为Url参数形式 paramMap中如果key为空(null和"")会被忽略,如果value为null,会被做为空白符("") 会自动url编码键和值decodeObject(String params, String charset) 将URL参数解析为Map(也可以解析Post中的键值对参数)将URL参数解析为Map(也可以解析Post中的键值对参数)static String编码URL,默认使用UTF-8编码 将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头static String用字符串字符串解码的变体.static String对URI中任何地方的所有非法字符或具有保留含义的字符进行编码.static String编码URL,默认使用UTF-8编码 将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头static String编码URL 将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头static StringencodeAuthority(String authority, String encoding) 用给定的编码编码给定的URI权限.static StringencodeAuthority(String authority, Charset charset) 用给定的编码编码给定的URI权限.static StringencodeFragment(String fragment, String encoding) 用给定的编码编码给定的URI片段.static StringencodeFragment(String fragment, Charset charset) 用给定的编码编码给定的URI片段.static StringencodeHost(String host, String encoding) 用给定的编码编码给定的URI主机.static StringencodeHost(String host, Charset charset) 用给定的编码编码给定的URI主机.static StringencodePath(String path, String encoding) 用给定的编码编码给定的URI路径.static StringencodePath(String path, Charset charset) 用给定的编码编码给定的URI路径.static StringencodePathSegment(String segment, String encoding) 用给定的编码编码给定的URI路径段.static StringencodePathSegment(String segment, Charset charset) 用给定的编码编码给定的URI路径段.static StringencodePort(String port, String encoding) 用给定的编码编码给定的URI端口。static StringencodePort(String port, Charset charset) 用给定的编码编码给定的URI端口。static StringencodeQuery(String url) 编码URL,默认使用UTF-8编码 将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头。static StringencodeQuery(String query, String encoding) 用给定的编码编码给定的URI查询.static StringencodeQuery(String query, Charset charset) 用给定的编码编码给定的URI查询.static StringencodeQueryParam(String queryParam, String encoding) 用给定的编码编码给定的URI查询参数.static StringencodeQueryParam(String queryParam, Charset charset) 用给定的编码编码给定的URI查询参数.static StringencodeScheme(String scheme, String encoding) 给定的编码编码给定的URI方案static StringencodeScheme(String scheme, Charset charset) 给定的编码编码给定的URI方案static Object[]encodeUriVariables(Object... uriVariables) 应用encode(String, java.nio.charset.Charset)到所有给定的URI变量值encodeUriVariables(Map<String, ?> uriVariables) 应用encode(String, java.nio.charset.Charset)到所有给定的URI变量值.static StringencodeUserInfo(String userInfo, String encoding) 用给定的编码编码给定的URI用户信息.static StringencodeUserInfo(String userInfo, Charset charset) 用给定的编码编码给定的URI用户信息.static String对URL参数做编码,只编码键和值 提供的值可以是url附带参数,但是不能只是urlstatic StringextractFileExtension(String path) 从给定的URI路径中提取文件扩展名.static String格式化URL链接获得authority部分获取编码,用于URLEncode和URLDecodestatic StringgetDecodedPath(URL url) 从URL对象中获取不被编码的路径Path 对于本地路径,URL对象的getPath方法对于包含中文或空格时会被编码,导致本读路径读取错误 此方法将URL转为URI后获取路径用于解决路径被编码的问题获取标识符,#后边的部分获取标识符,#后边的部分getHost()获取 主机,例如127.0.0.1static URI获取URL中域名部分,只保留URL中的协议(Protocol)、Host,其它为null。static JarFilegetJarFile(URL url) 从URL中获取JarFilegetPath()获取路径,例如/aa/bb/ccstatic String获得path部分获得路径,例如/aa/bb/ccintgetPort()获取端口,默认-1getQuery()获取查询语句,例如a=1&b=2获取查询语句,例如a=1&b=2static BufferedReader获得Reader获取协议,例如http获取协议,例如http,如果用户未定义协议,使用默认的http协议static InputStream从URL中获取流static URIgetStringURI(CharSequence content) 获取string协议的URL,类似于string:///xxxxxstatic URL获得URL,常用于使用绝对路径时的情况static URL[]获得URL,常用于使用绝对路径时的情况static URL获得URLstatic URL获得URLstatic boolean提供的URL是否为文件 文件协议包括"file", "vfsfile" 或 "vfs".static booleanisJarFileURL(URL url) 提供的URL是否为Jar文件URL 判断依据为file协议且扩展名为.jarstatic boolean提供的URL是否为jar包URL 协议包括: "jar", "zip", "vfszip" 或 "wsjar".static String标准化URL字符串,包括: 自动补齐“http://”头 去除开头的\或者/ 替换\为/static String标准化URL字符串,包括: 自动补齐“http://”头 去除开头的\或者/ 替换\为/static String标准化URL字符串,包括: 自动补齐“http://”头 去除开头的\或者/ 替换\为/static String标准化参数字符串,即URL中?static UriKitof()创建空的static UriKit使用URL字符串构建UriKit,当传入的URL没有协议时,按照http协议对待,编码默认使用UTF-8static UriKitof(String scheme, String host, int port, String path, String query, String fragment, Charset charset) 构建static UriKitof(String scheme, String host, int port, UriKit.Path path, UriKit.Query query, String fragment, Charset charset) 构建static UriKit使用URL字符串构建static UriKit使用URI构建static UriKit使用URL构建setCharset(Charset charset) 设置编码,用于URLEncode和URLDecodesetFragment(String fragment) 设置标识符,例如#后边的部分设置主机,例如127.0.0.1setPath(UriKit.Path path) 设置路径,例如/aa/bb/cc,将覆盖之前所有的path相关设置setPort(int port) 设置端口,默认-1setQuery(UriKit.Query query) 设置查询语句,例如a=1&b=2,将覆盖之前所有的query相关设置设置协议,例如httptoString()toURI()转换为URIstatic URI转字符串为URIstatic URI转URL为URItoURL()转换为URL对象static StringData URI Scheme封装。static StringData URI Scheme封装。toURL(URLStreamHandler handler) 转换为URL对象static URLtoUrlForHttp(String urlStr) 将URL字符串转换为URL对象,并做必要验证static URLtoUrlForHttp(String urlStr, URLStreamHandler handler) 将URL字符串转换为URL对象,并做必要验证static Stringstatic URL通过一个字符串形式的URL地址创建URL对象static URLurl(String url, URLStreamHandler handler) 通过一个字符串形式的URL地址创建URL对象static URLstatic String将表单数据字符串加到URL中(用于GET表单提交)static String将表单数据加到URL中(用于GET表单提交) 表单的键值对会被url编码,但是url中原参数不会被编码
-
Constructor Details
-
UriKit
public UriKit()构造 -
UriKit
public UriKit(String scheme, String host, int port, UriKit.Path path, UriKit.Query query, String fragment, Charset charset) 构造- Parameters:
scheme- 协议,默认httphost- 主机,例如127.0.0.1port- 端口,-1表示默认端口path- 路径,例如/aa/bb/ccquery- 查询,例如a=1&b=2fragment- 标识符例如#后边的部分charset- 编码,用于URLEncode和URLDecode
-
-
Method Details
-
of
-
of
-
of
-
of
-
of
-
of
public static UriKit of(String scheme, String host, int port, String path, String query, String fragment, Charset charset) 构建- Parameters:
scheme- 协议,默认httphost- 主机,例如127.0.0.1port- 端口,-1表示默认端口path- 路径,例如/aa/bb/ccquery- 查询,例如a=1&b=2fragment- 标识符例如#后边的部分charset- 编码,用于URLEncode和URLDecode- Returns:
- this
-
of
public static UriKit of(String scheme, String host, int port, UriKit.Path path, UriKit.Query query, String fragment, Charset charset) 构建- Parameters:
scheme- 协议,默认httphost- 主机,例如127.0.0.1port- 端口,-1表示默认端口path- 路径,例如/aa/bb/ccquery- 查询,例如a=1&b=2fragment- 标识符例如#后边的部分charset- 编码,用于URLEncode和URLDecode- Returns:
- this
-
url
-
url
- Parameters:
uri-URI- Returns:
- URL对象
- Throws:
InternalException-MalformedURLException包装,URI格式有问题时抛出- See Also:
-
url
通过一个字符串形式的URL地址创建URL对象- Parameters:
url- URLhandler-URLStreamHandler- Returns:
- URL对象
-
toUrlForHttp
-
toUrlForHttp
将URL字符串转换为URL对象,并做必要验证- Parameters:
urlStr- URL字符串handler-URLStreamHandler- Returns:
- URL
-
getURL
-
getURL
获得URL,常用于使用绝对路径时的情况- Parameters:
file- URL对应的文件对象- Returns:
- URL
- Throws:
InternalException- MalformedURLException
-
getURL
获得URL,常用于使用绝对路径时的情况- Parameters:
files- URL对应的文件对象- Returns:
- URL
- Throws:
InternalException- MalformedURLException
-
getURL
-
formatUrl
-
complateUrl
补全相对路径- Parameters:
baseUrl- 基准URLrelativePath- 相对URL- Returns:
- 相对路径
- Throws:
InternalException- MalformedURLException
-
encode
编码URL,默认使用UTF-8编码 将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头- Parameters:
url- URL- Returns:
- 编码后的URL
- Throws:
InternalException- UnsupportedEncodingException
-
encodeAll
-
encodeAll
-
getPath
获得path部分- Parameters:
uriStr- URI路径- Returns:
- path
- Throws:
InternalException- 包装URISyntaxException
-
getDecodedPath
-
toURI
转URL为URI- Parameters:
url- URL- Returns:
- URI
- Throws:
InternalException- 包装URISyntaxException
-
toURI
转字符串为URI- Parameters:
location- 字符串路径- Returns:
- URI
- Throws:
InternalException- 包装URISyntaxException
-
isFileURL
-
isJarURL
-
isJarFileURL
提供的URL是否为Jar文件URL 判断依据为file协议且扩展名为.jar- Parameters:
url- the URL to check- Returns:
- whether the URL has been identified as a JAR file URL
-
getStream
-
getReader
获得Reader- Parameters:
url-URLcharset- 编码- Returns:
BufferedReader
-
getJarFile
-
normalize
-
normalize
-
normalize
-
encodeScheme
-
encodeScheme
-
encodeAuthority
-
encodeAuthority
-
encodeUserInfo
-
encodeUserInfo
-
encodeHost
-
encodeHost
-
encodePort
-
encodePort
-
encodePath
-
encodePath
-
encodePathSegment
-
encodePathSegment
-
encodeQuery
-
encodeQuery
-
encodeQuery
-
encodeQueryParam
-
encodeQueryParam
-
encodeFragment
-
encodeFragment
-
encode
-
encode
-
encodeUriVariables
-
encodeUriVariables
应用encode(String, java.nio.charset.Charset)到所有给定的URI变量值- Parameters:
uriVariables- 要编码的URI变量值- Returns:
- 编码的字符串
-
uriDecode
-
decode
-
decode
解码给定的URI编码组件.See
uriDecode(String, java.nio.charset.Charset)for the decoding rules.- Parameters:
source- 编码的字符串encoding- 要使用的字符编码- Returns:
- 解码值
- Throws:
IllegalArgumentException- 当给定源包含无效的编码序列时
-
decode
解码给定的URI编码组件.- Parameters:
source- 编码的字符串charset- 要使用的字符编码- Returns:
- 解码值
- Throws:
IllegalArgumentException- 当给定源包含无效的编码序列时
-
extractFileExtension
-
encodeVal
-
normalize
-
decodeMap
-
decodeVal
-
decodeObject
-
withForm
-
withForm
-
getHost
-
toURL
Data URI Scheme封装。data URI scheme 允许我们使用内联(inline-code)的方式在网页中包含数据 目的是将一些小的数据,直接嵌入到网页中,从而不用再从外部文件载入。常用于将图片嵌入网页。- Parameters:
mediaType- 可选项(null表示无),数据类型(image/png、text/plain等)encoding- 数据编码方式(US-ASCII,BASE64等)data- 编码后的数据- Returns:
- Data URI字符串
-
toURL
Data URI Scheme封装。data URI scheme 允许我们使用内联(inline-code)的方式在网页中包含数据 目的是将一些小的数据,直接嵌入到网页中,从而不用再从外部文件载入。常用于将图片嵌入网页- Parameters:
mediaType- 可选项(null表示无),数据类型(image/png、text/plain等)charset- 可选项(null表示无),源文本的字符集编码方式encoding- 数据编码方式(US-ASCII,BASE64等)data- 编码后的数据- Returns:
- Data URI字符串
-
getStringURI
获取string协议的URL,类似于string:///xxxxx- Parameters:
content- 正文- Returns:
- URL
-
getScheme
-
setScheme
-
getSchemeWithDefault
-
getHost
-
setHost
-
getPort
public int getPort()获取端口,默认-1- Returns:
- 端口,默认-1
-
setPort
-
getAuthority
-
getPath
-
setPath
设置路径,例如/aa/bb/cc,将覆盖之前所有的path相关设置- Parameters:
path- 路径,例如/aa/bb/cc- Returns:
- this
-
getPathString
-
addPath
-
appendPath
-
getQuery
-
setQuery
设置查询语句,例如a=1&b=2,将覆盖之前所有的query相关设置- Parameters:
query- 查询语句,例如a=1&b=2- Returns:
- this
-
getQueryString
-
addQuery
-
getFragment
-
setFragment
-
getFragmentEncoded
-
getCharset
-
setCharset
-
build
-
toURL
-
toURL
转换为URL对象- Parameters:
handler-URLStreamHandler,null表示默认- Returns:
URL
-
toURI
-
toString
-