Class ResourceUtils
java.lang.Object
nl.basjes.parse.useragent.utils.springframework.util.ResourceUtils
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.
{link org.springframework.core.io.ResourceLoader}'s getResource()
method can resolve any location to a {link org.springframework.core.io.Resource}
object, which in turn allows one to obtain a java.io.File
in the
file system through its getFile()
method.
- Since:
- 1.1.5
- Author:
- Juergen Hoeller see org.springframework.core.io.Resource see org.springframework.core.io.ClassPathResource see org.springframework.core.io.FileSystemResource see org.springframework.core.io.UrlResource see org.springframework.core.io.ResourceLoader
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Pseudo URL prefix for loading from the class path: "classpath:".static final String
URL prefix for loading from the file system: "file:".static final String
URL prefix for loading from a jar file: "jar:".static final String
Separator between JAR URL and file path within the JAR: "!/".static final String
URL protocol for a file in the file system: "file".static final String
URL protocol for an entry from a jar file: "jar".static final String
URL protocol for a general JBoss VFS resource: "vfs".static final String
URL protocol for a JBoss file system resource: "vfsfile".static final String
URL protocol for an entry from a JBoss jar file: "vfszip".static final String
URL protocol for an entry from a war file: "war".static final String
URL protocol for an entry from a WebSphere jar file: "wsjar".static final String
URL protocol for an entry from a zip file: "zip".static final String
Special separator between WAR URL and jar part on Tomcat. -
Method Summary
Modifier and TypeMethodDescriptionstatic File
Resolve the given resource URI to ajava.io.File
, i.e.static File
Resolve the given resource URL to ajava.io.File
, i.e.static boolean
Determine whether the given URL points to a resource in the file system, i.e.static boolean
Determine whether the given URL points to a resource in a jar file.static URI
Create a URI instance for the given location String, replacing spaces with "%20" URI encoding first.static URI
Create a URI instance for the given URL, replacing spaces with "%20" URI encoding first.static void
Set the {link URLConnection#setUseCaches "useCaches"} flag on the given connection, preferringfalse
but leaving the flag attrue
for JNLP based resources.
-
Field Details
-
CLASSPATH_URL_PREFIX
Pseudo URL prefix for loading from the class path: "classpath:".- See Also:
-
FILE_URL_PREFIX
URL prefix for loading from the file system: "file:".- See Also:
-
JAR_URL_PREFIX
URL prefix for loading from a jar file: "jar:".- See Also:
-
URL_PROTOCOL_FILE
URL protocol for a file in the file system: "file".- See Also:
-
URL_PROTOCOL_JAR
URL protocol for an entry from a jar file: "jar".- See Also:
-
URL_PROTOCOL_WAR
URL protocol for an entry from a war file: "war".- See Also:
-
URL_PROTOCOL_ZIP
URL protocol for an entry from a zip file: "zip".- See Also:
-
URL_PROTOCOL_WSJAR
URL protocol for an entry from a WebSphere jar file: "wsjar".- See Also:
-
URL_PROTOCOL_VFSZIP
URL protocol for an entry from a JBoss jar file: "vfszip".- See Also:
-
URL_PROTOCOL_VFSFILE
URL protocol for a JBoss file system resource: "vfsfile".- See Also:
-
URL_PROTOCOL_VFS
URL protocol for a general JBoss VFS resource: "vfs".- See Also:
-
JAR_URL_SEPARATOR
Separator between JAR URL and file path within the JAR: "!/".- See Also:
-
WAR_URL_SEPARATOR
Special separator between WAR URL and jar part on Tomcat.- See Also:
-
-
Method Details
-
getFile
Resolve the given resource URL to ajava.io.File
, i.e. to a file in the file system.- Parameters:
resourceUrl
- the resource URL to resolvedescription
- a description of the original resource that the URL was created for (for example, a class path location)- Returns:
- a corresponding File object
- Throws:
FileNotFoundException
- if the URL cannot be resolved to a file in the file system
-
getFile
Resolve the given resource URI to ajava.io.File
, i.e. to a file in the file system.- Parameters:
resourceUri
- the resource URI to resolvedescription
- a description of the original resource that the URI was created for (for example, a class path location)- Returns:
- a corresponding File object
- Throws:
FileNotFoundException
- if the URL cannot be resolved to a file in the file system- Since:
- 2.5
-
isFileURL
Determine whether the given URL points to a resource in the file system, i.e. has protocol "file", "vfsfile" or "vfs".- Parameters:
url
- the URL to check- Returns:
- 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".- Parameters:
url
- the URL to check- Returns:
- whether the URL has been identified as a JAR URL
-
toURI
Create a URI instance for the given URL, replacing spaces with "%20" URI encoding first.- Parameters:
url
- the URL to convert into a URI instance- Returns:
- the URI instance
- Throws:
URISyntaxException
- if the URL wasn't a valid URI see java.net.URL#toURI()
-
toURI
Create a URI instance for the given location String, replacing spaces with "%20" URI encoding first.- Parameters:
location
- the location String to convert into a URI instance- Returns:
- the URI instance
- Throws:
URISyntaxException
- if the location wasn't a valid URI
-
useCachesIfNecessary
Set the {link URLConnection#setUseCaches "useCaches"} flag on the given connection, preferringfalse
but leaving the flag attrue
for JNLP based resources.- Parameters:
con
- the URLConnection to set the flag on
-