类 ResourceUtils
java.lang.Object
cn.taketoday.util.ResourceUtils
- 从以下版本开始:
- 2.1.6
- 作者:
- TODAY 2019-05-15 13:37
-
字段概要
字段修饰符和类型字段说明static final StringPseudo URL prefix for loading from the class path: "classpath:".static final StringURL prefix for loading from the file system: "file:".static final Stringstatic final StringFile extension for a regular jar file: ".jar".static final Stringstatic final StringURL prefix for loading from a jar file: "jar:".static final StringSeparator between JAR URL and file path within the JAR: "!static final StringURL protocol for a file in the file system: "file".static final StringURL protocol for an entry from a jar file: "jar".static final StringURL protocol for a JBoss file system resource: "vfsfile".static final StringURL protocol for an entry from a JBoss jar file: "vfszip".static final StringURL protocol for an entry from a war file: "war".static final StringURL protocol for an entry from a WebSphere jar file: "wsjar".static final StringURL protocol for an entry from a zip file: "zip".static final StringURL prefix for loading from a war file on Tomcat: "war:".static final StringSpecial separator between WAR URL and jar part on Tomcat. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static URLextractArchiveURL(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 URLextractJarFileURL(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 FileResolve the given resource location to ajava.io.File, i.e. to a file in the file system.static FileResolve the given resource URI to ajava.io.File, i.e. to a file in the file system.static FileResolve the given resource URI to ajava.io.File, i.e. to a file in the file system.static FileResolve the given resource URL to ajava.io.File, i.e. to a file in the file system.static FileResolve the given resource URL to ajava.io.File, i.e. to a file in the file system.static ResourcegetResource(File file) GetResourcefrom a filestatic ResourcegetResource(String location) GetResourcewith given locationstatic ResourcegetResource(URL url) static InputStreamgetResourceAsStream(String resourceLocation) Get aInputStreamfrom given resource stringstatic Resource[]getResources(String pathPattern) Resolve the given location pattern into Resource objects.static Resource[]getResources(String pathPattern, ClassLoader classLoader) Resolve the given location pattern into Resource objects.static URLResolve the given resource location to ajava.net.URL.static booleanDetermine whether the given URL points to a resource in the file system, i.e.static booleanisJarFileURL(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 booleanDetermine whether the given URL points to a resource in a jar file. i.e. has protocol "jar", "war, ""zip", "vfszip" or "wsjar".static booleanReturn whether the given resource location is a URL: either a special "classpath" pseudo URL or a standard URL.static URLtoRelativeURL(URL root, String relativePath) Create a URL instance for the given root URL and relative path, going through URI construction and then URL conversion.static URICreate a URI instance for the given location String, replacing spaces with "%20" URI encoding first.static URICreate a URI instance for the given URL, replacing spaces with "%20" URI encoding first.static URLCreate a URL instance for the given location String, going through URI construction and then URL conversion.static voidSet the"useCaches"flag on the given connection, preferringfalsebut leaving the flag attruefor JNLP based resources.
-
字段详细资料
-
CLASSPATH_URL_PREFIX
Pseudo URL prefix for loading from the class path: "classpath:".- 另请参阅:
-
JAR_ENTRY_URL_PREFIX
- 另请参阅:
-
JAR_SEPARATOR
- 另请参阅:
-
FILE_URL_PREFIX
URL prefix for loading from the file system: "file:".- 另请参阅:
-
JAR_URL_PREFIX
URL prefix for loading from a jar file: "jar:".- 另请参阅:
-
WAR_URL_PREFIX
URL prefix for loading from a war file on Tomcat: "war:".- 另请参阅:
-
URL_PROTOCOL_FILE
URL protocol for a file in the file system: "file".- 另请参阅:
-
URL_PROTOCOL_JAR
URL protocol for an entry from a jar file: "jar".- 另请参阅:
-
URL_PROTOCOL_WAR
URL protocol for an entry from a war file: "war".- 另请参阅:
-
URL_PROTOCOL_ZIP
URL protocol for an entry from a zip file: "zip".- 另请参阅:
-
URL_PROTOCOL_WSJAR
URL protocol for an entry from a WebSphere jar file: "wsjar".- 另请参阅:
-
URL_PROTOCOL_VFSZIP
URL protocol for an entry from a JBoss jar file: "vfszip".- 另请参阅:
-
URL_PROTOCOL_VFSFILE
URL protocol for a JBoss file system resource: "vfsfile".- 另请参阅:
-
JAR_FILE_EXTENSION
File extension for a regular jar file: ".jar".- 另请参阅:
-
JAR_URL_SEPARATOR
Separator between JAR URL and file path within the JAR: "!/".- 另请参阅:
-
WAR_URL_SEPARATOR
Special separator between WAR URL and jar part on Tomcat.- 另请参阅:
-
-
构造器详细资料
-
ResourceUtils
public ResourceUtils()
-
-
方法详细资料
-
getResources
Resolve the given location pattern into Resource objects.Overlapping resource entries that point to the same physical resource should be avoided, as far as possible. The result should have set semantics.
- 参数:
pathPattern- The location pattern to resolve- 返回:
- the corresponding Resource objects
- 抛出:
IOException- in case of I/O errors
-
getResources
public static Resource[] getResources(String pathPattern, @Nullable ClassLoader classLoader) throws IOException Resolve the given location pattern into Resource objects.Overlapping resource entries that point to the same physical resource should be avoided, as far as possible. The result should have set semantics.
- 参数:
pathPattern- The location pattern to resolveclassLoader- TheClassLoaderto search (including its ancestors)- 返回:
- the corresponding Resource objects
- 抛出:
IOException- in case of I/O errors
-
getResource
GetResourcewith given location- 参数:
location- resource location
-
getResource
-
getResource
GetResourcefrom a file- 参数:
file- source- 返回:
- a
FileSystemResource
-
isFileURL
Determine whether the given URL points to a resource in the file system, i.e. has protocol "file".- 参数:
url- the URL to check- 返回:
- whether the URL has been identified as a file system URL
-
isJarURL
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
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
-
extractJarFileURL
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).- 参数:
jarUrl- the original URL- 返回:
- the URL for the actual jar file
- 抛出:
MalformedURLException- if no valid jar file URL could be extracted
-
useCachesIfNecessary
Set the"useCaches"flag on the given connection, preferringfalsebut leaving the flag attruefor JNLP based resources.- 参数:
con- the URLConnection to set the flag on
-
toURI
Create 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
- 抛出:
URISyntaxException- if the URL wasn't a valid URI- 另请参阅:
-
toURI
Create 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
- 抛出:
URISyntaxException- if the location wasn't a valid URI
-
isUrl
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
- 另请参阅:
-
extractArchiveURL
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).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
- 抛出:
MalformedURLException- if no valid jar file URL could be extracted- 另请参阅:
-
getResourceAsStream
Get aInputStreamfrom given resource string- 参数:
resourceLocation- Target resource string- 返回:
- A
InputStream - 抛出:
IOException- If any IOExceptionoccurred- 从以下版本开始:
- 4.0
-
getURL
Resolve the given resource location to ajava.net.URL.Does not check whether the URL actually exists; simply returns the URL 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 URL object
- 抛出:
FileNotFoundException- if the resource cannot be resolved to a URL- 从以下版本开始:
- 4.0
-
getFile
Resolve 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
- 抛出:
FileNotFoundException- if the resource cannot be resolved to a file in the file system- 从以下版本开始:
- 4.0
-
getFile
Resolve 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
- 抛出:
FileNotFoundException- if the URL cannot be resolved to a file in the file system- 从以下版本开始:
- 4.0
-
getFile
Resolve 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
- 抛出:
FileNotFoundException- if the URL cannot be resolved to a file in the file system- 从以下版本开始:
- 4.0
-
getFile
Resolve 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
- 抛出:
FileNotFoundException- if the URL cannot be resolved to a file in the file system- 从以下版本开始:
- 4.0
-
getFile
Resolve 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
- 抛出:
FileNotFoundException- if the URL cannot be resolved to a file in the file system- 从以下版本开始:
- 4.0
-
toURL
Create a URL instance for the given location String, going through URI construction and then URL conversion.- 参数:
location- the location String to convert into a URL instance- 返回:
- the URL instance
- 抛出:
MalformedURLException- if the location wasn't a valid URL- 从以下版本开始:
- 4.0
-
toRelativeURL
Create a URL instance for the given root URL and relative path, going through URI construction and then URL conversion.- 参数:
root- the root URL to start fromrelativePath- the relative path to apply- 返回:
- the relative URL instance
- 抛出:
MalformedURLException- if the end result is not a valid URL- 从以下版本开始:
- 4.0
-