public class URLUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CLASSPATH_URL_PREFIX
针对ClassPath路径的伪协议前缀(兼容Spring): "classpath:"
|
static String |
FILE_URL_PREFIX
URL 前缀表示文件: "file:"
|
static String |
JAR_URL_PREFIX
URL 前缀表示jar: "jar:"
|
static String |
JAR_URL_SEPARATOR
Jar路径以及内部文件路径的分界符: "!/"
|
static String |
URL_PROTOCOL_FILE
URL 协议表示文件: "file"
|
static String |
URL_PROTOCOL_JAR
URL 协议表示Jar文件: "jar"
|
static String |
URL_PROTOCOL_VFS
URL 协议表示JBoss VFS资源: "vfs"
|
static String |
URL_PROTOCOL_VFSFILE
URL 协议表示JBoss文件: "vfsfile"
|
static String |
URL_PROTOCOL_VFSZIP
URL 协议表示JBoss zip文件: "vfszip"
|
static String |
URL_PROTOCOL_WSJAR
URL 协议表示WebSphere文件: "wsjar"
|
static String |
URL_PROTOCOL_ZIP
URL 协议表示zip文件: "zip"
|
static String |
WAR_URL_PREFIX
URL 前缀表示war: "war:"
|
static String |
WAR_URL_SEPARATOR
WAR路径及内部文件路径分界符
|
| Constructor and Description |
|---|
URLUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
complateUrl(String baseUrl,
String relativePath)
补全相对路径
|
static String |
decode(String url)
解码URL
将%开头的16进制表示的内容解码。
|
static String |
decode(String url,
String charset)
解码URL
将%开头的16进制表示的内容解码。
|
static String |
encode(String url)
编码URL,默认使用UTF-8编码
将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头。
|
static String |
encode(String url,
String charset)
编码URL
将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头。
|
static String |
formatUrl(String url)
格式化URL链接
|
static String |
getDecodedPath(URL url)
从URL对象中获取不被编码的路径Path
对于本地路径,URL对象的getPath方法对于包含中文或空格时会被编码,导致本读路径读取错误。
此方法将URL转为URI后获取路径用于解决路径被编码的问题
|
static JarFile |
getJarFile(URL url)
从URL中获取JarFile
|
static String |
getPath(String uriStr)
获得path部分
|
static BufferedReader |
getReader(URL url,
Charset charset)
获得Reader
|
static InputStream |
getStream(URL url)
从URL中获取流
|
static URL |
getURL(File file)
获得URL,常用于使用绝对路径时的情况
|
static URL |
getURL(String pathBaseClassLoader)
获得URL
|
static URL |
getURL(String path,
Class<?> clazz)
获得URL
|
static URL[] |
getURLs(File... files)
获得URL,常用于使用绝对路径时的情况
|
static boolean |
isFileURL(URL url)
提供的URL是否为文件
文件协议包括"file", "vfsfile" 或 "vfs".
|
static boolean |
isJarFileURL(URL url)
提供的URL是否为Jar文件URL 判断依据为file协议且扩展名为.jar
|
static boolean |
isJarURL(URL url)
提供的URL是否为jar包URL 协议包括: "jar", "zip", "vfszip" 或 "wsjar".
|
static String |
normalize(String url)
标准化URL字符串,包括:
|
static URI |
toURI(String location)
转字符串为URI
|
static URI |
toURI(URL url)
转URL为URI
|
static URL |
toUrlForHttp(String urlStr)
将URL字符串转换为URL对象,并做必要验证
|
static URL |
toUrlForHttp(String urlStr,
URLStreamHandler handler)
将URL字符串转换为URL对象,并做必要验证
|
static URL |
url(String url)
通过一个字符串形式的URL地址创建URL对象
|
static URL |
url(String url,
URLStreamHandler handler)
通过一个字符串形式的URL地址创建URL对象
|
public static final String CLASSPATH_URL_PREFIX
public static final String FILE_URL_PREFIX
public static final String JAR_URL_PREFIX
public static final String WAR_URL_PREFIX
public static final String URL_PROTOCOL_FILE
public static final String URL_PROTOCOL_JAR
public static final String URL_PROTOCOL_ZIP
public static final String URL_PROTOCOL_WSJAR
public static final String URL_PROTOCOL_VFSZIP
public static final String URL_PROTOCOL_VFSFILE
public static final String URL_PROTOCOL_VFS
public static final String JAR_URL_SEPARATOR
public static final String WAR_URL_SEPARATOR
public static URL url(String url, URLStreamHandler handler)
url - URLhandler - URLStreamHandlerpublic static URL toUrlForHttp(String urlStr)
urlStr - URL字符串public static URL toUrlForHttp(String urlStr, URLStreamHandler handler)
urlStr - URL字符串handler - URLStreamHandlerpublic static URL getURL(String pathBaseClassLoader)
pathBaseClassLoader - 相对路径(相对于classes)ResourceUtils.getResource(String)public static URL getURL(String path, Class<?> clazz)
path - 相对给定 class所在的路径clazz - 指定classResourceUtils.getResource(String, Class)public static URL getURL(File file)
file - URL对应的文件对象CommonException - MalformedURLExceptionpublic static URL[] getURLs(File... files)
files - URL对应的文件对象CommonException - MalformedURLExceptionpublic static String formatUrl(String url)
url - 需要格式化的URLnormalize(String)public static String complateUrl(String baseUrl, String relativePath)
baseUrl - 基准URLrelativePath - 相对URLCommonException - MalformedURLExceptionpublic static String encode(String url) throws CommonException
url - URLCommonException - UnsupportedEncodingExceptionpublic static String encode(String url, String charset) throws CommonException
url - URLcharset - 编码CommonException - UnsupportedEncodingExceptionpublic static String decode(String url) throws CommonException
url - URLCommonException - UnsupportedEncodingExceptionpublic static String decode(String url, String charset) throws CommonException
url - URLcharset - 编码CommonException - UnsupportedEncodingExceptionpublic static String getPath(String uriStr)
uriStr - URI路径CommonException - 包装URISyntaxExceptionpublic static String getDecodedPath(URL url)
url - URLpublic static URI toURI(URL url) throws CommonException
url - URLCommonException - 包装URISyntaxExceptionpublic static URI toURI(String location) throws CommonException
location - 字符串路径CommonException - 包装URISyntaxExceptionpublic static boolean isFileURL(URL url)
url - URLpublic static boolean isJarURL(URL url)
url - URLpublic static boolean isJarFileURL(URL url)
url - the URL to checkpublic static InputStream getStream(URL url)
url - URLpublic static BufferedReader getReader(URL url, Charset charset)
url - URLcharset - 编码BufferedReaderpublic static JarFile getJarFile(URL url)
url - URLCopyright © 2019. All rights reserved.