类 ResourceUtils
- java.lang.Object
-
- com.alibaba.nacos.common.packagescan.util.ResourceUtils
-
public abstract class ResourceUtils extends java.lang.ObjectCopy from https://github.com/spring-projects/spring-framework.git, with less modifications Utility methods for resolving resource locations to files in the file system. Mainly for internal use within the framework.Consider using Spring's Resource abstraction in the core package for handling all kinds of file resources in a uniform manner. method can resolve any location to a
Resourceobject, which in turn allows one to obtain ajava.io.Filein the file system through itsgetFile()method.- 从以下版本开始:
- 1.1.5
- 作者:
- Juergen Hoeller
-
-
字段概要
字段 修饰符和类型 字段 说明 static java.lang.StringCLASSPATH_URL_PREFIXPseudo URL prefix for loading from the class path: "classpath:".static java.lang.StringFILE_URL_PREFIXURL prefix for loading from the file system: "file:".static java.lang.StringJAR_FILE_EXTENSIONFile extension for a regular jar file: ".jar".static java.lang.StringJAR_URL_PREFIXURL prefix for loading from a jar file: "jar:".static java.lang.StringJAR_URL_SEPARATORSeparator between JAR URL and file path within the JAR: "!static java.lang.StringURL_PROTOCOL_FILEURL protocol for a file in the file system: "file".static java.lang.StringURL_PROTOCOL_JARURL protocol for an entry from a jar file: "jar".static java.lang.StringURL_PROTOCOL_VFSURL protocol for a general JBoss VFS resource: "vfs".static java.lang.StringURL_PROTOCOL_VFSFILEURL protocol for a JBoss file system resource: "vfsfile".static java.lang.StringURL_PROTOCOL_VFSZIPURL protocol for an entry from a JBoss jar file: "vfszip".static java.lang.StringURL_PROTOCOL_WARURL protocol for an entry from a war file: "war".static java.lang.StringURL_PROTOCOL_WSJARURL protocol for an entry from a WebSphere jar file: "wsjar".static java.lang.StringURL_PROTOCOL_ZIPURL protocol for an entry from a zip file: "zip".static java.lang.StringWAR_URL_PREFIXURL prefix for loading from a war file on Tomcat: "war:".static java.lang.StringWAR_URL_SEPARATORSpecial separator between WAR URL and jar part on Tomcat.
-
构造器概要
构造器 构造器 说明 ResourceUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static java.net.URLextractArchiveUrl(java.net.URL jarUrl)Extract the URL for the outermost archive from the given jar/war URL (which may point to a resource in a jar file or to a jar file itself).static java.net.URLextractJarFileUrl(java.net.URL jarUrl)Extract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself).static java.io.FilegetFile(java.lang.String resourceLocation)Resolve the given resource location to ajava.io.File, i.e. to a file in the file system.static java.io.FilegetFile(java.net.URI resourceUri)Resolve the given resource URI to ajava.io.File, i.e. to a file in the file system.static java.io.FilegetFile(java.net.URI resourceUri, java.lang.String description)Resolve the given resource URI to ajava.io.File, i.e. to a file in the file system.static java.io.FilegetFile(java.net.URL resourceUrl)Resolve the given resource URL to ajava.io.File, i.e. to a file in the file system.static java.io.FilegetFile(java.net.URL resourceUrl, java.lang.String description)Resolve the given resource URL to ajava.io.File, i.e. to a file in the file system.static booleanisFileUrl(java.net.URL url)Determine whether the given URL points to a resource in the file system, i.e. has protocol "file", "vfsfile" or "vfs".static booleanisJarFileUrl(java.net.URL url)Determine whether the given URL points to a jar file itself, that is, has protocol "file" and ends with the ".jar" extension.static booleanisJarUrl(java.net.URL url)Determine whether the given URL points to a resource in a jar file.static booleanisUrl(java.lang.String resourceLocation)Return whether the given resource location is a URL: either a special "classpath" pseudo URL or a standard URL.static java.net.URItoUri(java.lang.String location)Create a URI instance for the given location String, replacing spaces with "%20" URI encoding first.static java.net.URItoUri(java.net.URL url)Create a URI instance for the given URL, replacing spaces with "%20" URI encoding first.static voiduseCachesIfNecessary(java.net.URLConnection con)Set the"useCaches"flag on the given connection, preferringfalsebut leaving the flag attruefor JNLP based resources.
-
-
-
字段详细资料
-
CLASSPATH_URL_PREFIX
public static final java.lang.String CLASSPATH_URL_PREFIX
Pseudo URL prefix for loading from the class path: "classpath:".- 另请参阅:
- 常量字段值
-
FILE_URL_PREFIX
public static final java.lang.String FILE_URL_PREFIX
URL prefix for loading from the file system: "file:".- 另请参阅:
- 常量字段值
-
JAR_URL_PREFIX
public static final java.lang.String JAR_URL_PREFIX
URL prefix for loading from a jar file: "jar:".- 另请参阅:
- 常量字段值
-
WAR_URL_PREFIX
public static final java.lang.String WAR_URL_PREFIX
URL prefix for loading from a war file on Tomcat: "war:".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_FILE
public static final java.lang.String URL_PROTOCOL_FILE
URL protocol for a file in the file system: "file".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_JAR
public static final java.lang.String URL_PROTOCOL_JAR
URL protocol for an entry from a jar file: "jar".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_WAR
public static final java.lang.String URL_PROTOCOL_WAR
URL protocol for an entry from a war file: "war".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_ZIP
public static final java.lang.String URL_PROTOCOL_ZIP
URL protocol for an entry from a zip file: "zip".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_WSJAR
public static final java.lang.String URL_PROTOCOL_WSJAR
URL protocol for an entry from a WebSphere jar file: "wsjar".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_VFSZIP
public static final java.lang.String URL_PROTOCOL_VFSZIP
URL protocol for an entry from a JBoss jar file: "vfszip".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_VFSFILE
public static final java.lang.String URL_PROTOCOL_VFSFILE
URL protocol for a JBoss file system resource: "vfsfile".- 另请参阅:
- 常量字段值
-
URL_PROTOCOL_VFS
public static final java.lang.String URL_PROTOCOL_VFS
URL protocol for a general JBoss VFS resource: "vfs".- 另请参阅:
- 常量字段值
-
JAR_FILE_EXTENSION
public static final java.lang.String JAR_FILE_EXTENSION
File extension for a regular jar file: ".jar".- 另请参阅:
- 常量字段值
-
JAR_URL_SEPARATOR
public static final java.lang.String JAR_URL_SEPARATOR
Separator between JAR URL and file path within the JAR: "!/".- 另请参阅:
- 常量字段值
-
WAR_URL_SEPARATOR
public static final java.lang.String WAR_URL_SEPARATOR
Special separator between WAR URL and jar part on Tomcat.- 另请参阅:
- 常量字段值
-
-
方法详细资料
-
isUrl
public static boolean isUrl(java.lang.String resourceLocation)
Return whether the given resource location is a URL: either a special "classpath" pseudo URL or a standard URL.- 参数:
resourceLocation- the location String to check- 返回:
- whether the location qualifies as a URL
- 另请参阅:
CLASSPATH_URL_PREFIX,URL
-
getFile
public static java.io.File getFile(java.lang.String resourceLocation) throws java.io.FileNotFoundExceptionResolve the given resource location to ajava.io.File, i.e. to a file in the file system.Does not check whether the file actually exists; simply returns the File that the given location would correspond to.
- 参数:
resourceLocation- the resource location to resolve: either a "classpath:" pseudo URL, a "file:" URL, or a plain file path- 返回:
- a corresponding File object
- 抛出:
java.io.FileNotFoundException- if the resource cannot be resolved to a file in the file system
-
getFile
public static java.io.File getFile(java.net.URL resourceUrl) throws java.io.FileNotFoundExceptionResolve the given resource URL to ajava.io.File, i.e. to a file in the file system.- 参数:
resourceUrl- the resource URL to resolve- 返回:
- a corresponding File object
- 抛出:
java.io.FileNotFoundException- if the URL cannot be resolved to a file in the file system
-
getFile
public static java.io.File getFile(java.net.URL resourceUrl, java.lang.String description) throws java.io.FileNotFoundExceptionResolve the given resource URL to ajava.io.File, i.e. to a file in the file system.- 参数:
resourceUrl- the resource URL to resolvedescription- a description of the original resource that the URL was created for (for example, a class path location)- 返回:
- a corresponding File object
- 抛出:
java.io.FileNotFoundException- if the URL cannot be resolved to a file in the file system
-
getFile
public static java.io.File getFile(java.net.URI resourceUri) throws java.io.FileNotFoundExceptionResolve the given resource URI to ajava.io.File, i.e. to a file in the file system.- 参数:
resourceUri- the resource URI to resolve- 返回:
- a corresponding File object
- 抛出:
java.io.FileNotFoundException- if the URL cannot be resolved to a file in the file system- 从以下版本开始:
- 2.5
-
getFile
public static java.io.File getFile(java.net.URI resourceUri, java.lang.String description) throws java.io.FileNotFoundExceptionResolve the given resource URI to ajava.io.File, i.e. to a file in the file system.- 参数:
resourceUri- the resource URI to resolvedescription- a description of the original resource that the URI was created for (for example, a class path location)- 返回:
- a corresponding File object
- 抛出:
java.io.FileNotFoundException- if the URL cannot be resolved to a file in the file system- 从以下版本开始:
- 2.5
-
isFileUrl
public static boolean isFileUrl(java.net.URL url)
Determine whether the given URL points to a resource in the file system, i.e. has protocol "file", "vfsfile" or "vfs".- 参数:
url- the URL to check- 返回:
- whether the URL has been identified as a file system URL
-
isJarUrl
public static boolean isJarUrl(java.net.URL url)
Determine whether the given URL points to a resource in a jar file. i.e. has protocol "jar", "war, ""zip", "vfszip" or "wsjar".- 参数:
url- the URL to check- 返回:
- whether the URL has been identified as a JAR URL
-
isJarFileUrl
public static boolean isJarFileUrl(java.net.URL url)
Determine whether the given URL points to a jar file itself, that is, has protocol "file" and ends with the ".jar" extension.- 参数:
url- the URL to check- 返回:
- whether the URL has been identified as a JAR file URL
- 从以下版本开始:
- 4.1
-
extractJarFileUrl
public static java.net.URL extractJarFileUrl(java.net.URL jarUrl) throws java.net.MalformedURLExceptionExtract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself).- 参数:
jarUrl- the original URL- 返回:
- the URL for the actual jar file
- 抛出:
java.net.MalformedURLException- if no valid jar file URL could be extracted
-
extractArchiveUrl
public static java.net.URL extractArchiveUrl(java.net.URL jarUrl) throws java.net.MalformedURLExceptionExtract the URL for the outermost archive from the given jar/war URL (which may point to a resource in a jar file or to a jar file itself).In the case of a jar file nested within a war file, this will return a URL to the war file since that is the one resolvable in the file system.
- 参数:
jarUrl- the original URL- 返回:
- the URL for the actual jar file
- 抛出:
java.net.MalformedURLException- if no valid jar file URL could be extracted- 从以下版本开始:
- 4.1.8
- 另请参阅:
extractJarFileUrl(URL)
-
toUri
public static java.net.URI toUri(java.net.URL url) throws java.net.URISyntaxExceptionCreate a URI instance for the given URL, replacing spaces with "%20" URI encoding first.- 参数:
url- the URL to convert into a URI instance- 返回:
- the URI instance
- 抛出:
java.net.URISyntaxException- if the URL wasn't a valid URI- 另请参阅:
URL.toURI()
-
toUri
public static java.net.URI toUri(java.lang.String location) throws java.net.URISyntaxExceptionCreate a URI instance for the given location String, replacing spaces with "%20" URI encoding first.- 参数:
location- the location String to convert into a URI instance- 返回:
- the URI instance
- 抛出:
java.net.URISyntaxException- if the location wasn't a valid URI
-
useCachesIfNecessary
public static void useCachesIfNecessary(java.net.URLConnection con)
Set the"useCaches"flag on the given connection, preferringfalsebut leaving the flag attruefor JNLP based resources.- 参数:
con- the URLConnection to set the flag on
-
-