类 URLUtils
java.lang.Object
com.dtflys.forest.utils.URLUtils
- 从以下版本开始:
- 2017-05-17 16:35
- 作者:
- gongjun[jun.gong@thebeastshop.com]
-
方法概要
修饰符和类型方法说明static String强制URL Encoding编码static voidcheckBaseURL(String baseUrl) static String进行URL Encoding编码static StringgetValidBaseURL(String baseUrl) static StringgetValidURL(String baseURL, String uri) 获取合法的URL字符串static booleanhasProtocol(String url) URL字符串中是否包含HTTP协议部分static boolean判断字符串是否已被URL Encoding编码过static booleanisNonePort(Integer port) 判断端口号是否为空static booleanisNotNonePort(Integer port) 判断端口号是否不为空static boolean判断字符串是否是一个URLstatic booleanisValidUrl(String url) 判断字符串是否为合法的URLstatic StringpathEncode(String content, String encode) 进行URI路径的URL Encoding编码static StringqueryValueEncode(String content, String encode) 进行查询参数值部分的URL Encoding编码static StringqueryValueWithBraceEncode(String content, String encode) 进行 (带不转义大括号的) 查询参数值部分的URL Encoding编码static String进行URI ref的URL Encoding编码static StringuserInfoEncode(String content, String encode) 进行用户验证信息的URL Encoding编码
-
方法详细资料
-
isURL
判断字符串是否是一个URL- 参数:
str- 被判断的字符串- 返回:
true: 是URL,false: 不是URL
-
hasProtocol
URL字符串中是否包含HTTP协议部分- 参数:
url- 需要被判断的URL字符串- 返回:
true: 包含HTTP协议,false: 不包含
-
isValidUrl
判断字符串是否为合法的URL- 参数:
url- 被判断的URL字符串- 返回:
true: 合法,false: 不合法
-
checkBaseURL
-
getValidBaseURL
-
getValidURL
获取合法的URL字符串若 uri 参数不合法,即不包含协议头以及域名/主机名/ip地址部分,则和 baseURL 参数进行合并
若 uri 参数已经是一个合法的URL字符串,则直接返回
- 参数:
baseURL- 根URL字符串uri- URL字符串- 返回:
- 合法的URL字符串
-
isNonePort
判断端口号是否为空- 参数:
port- 端口号- 返回:
true: 空端口,false: 不为空
-
isNotNonePort
判断端口号是否不为空- 参数:
port- 端口号- 返回:
true: 不为空,false: 空端口
-
allEncode
强制URL Encoding编码- 参数:
content- 需要编码的原字符串encode- 编码字符集- 返回:
- URL Encoding编码结果字符串
-
userInfoEncode
进行用户验证信息的URL Encoding编码- 参数:
content- 需要编码的原字符串encode- 编码字符集- 返回:
- URL Encoding编码结果字符串
-
pathEncode
进行URI路径的URL Encoding编码- 参数:
content- 需要编码的原字符串encode- 编码字符集- 返回:
- URL Encoding编码结果字符串
-
refEncode
进行URI ref的URL Encoding编码- 参数:
content- 需要编码的原字符串encode- 编码字符集- 返回:
- URL Encoding编码结果字符串
-
queryValueEncode
进行查询参数值部分的URL Encoding编码- 参数:
content- 需要编码的原字符串encode- 编码字符集- 返回:
- URL Encoding编码结果字符串
-
queryValueWithBraceEncode
进行 (带不转义大括号的) 查询参数值部分的URL Encoding编码- 参数:
content- 需要编码的原字符串encode- 编码字符集- 返回:
- URL Encoding编码结果字符串
-
encode
进行URL Encoding编码该方法不会强制进行编码,即某些不需要编码的情况就不会去做URL Encoding
如一个合法的URL字符串就不会被编码
- 参数:
content- 需要编码的原字符串charset- 编码字符集- 返回:
- URL Encoding编码结果字符串
- 抛出:
UnsupportedEncodingException- 编码过程中可能抛出的异常
-
isEncoded
判断字符串是否已被URL Encoding编码过- 参数:
content- 被判断的原字符串- 返回:
true: 被编码过,false: 未被编码过
-