public class ResourceUtils extends Object
Stream-backed resources.
getInputStreamForPath(String)
| Modifier and Type | Field and Description |
|---|---|
static String |
CLASSPATH_PREFIX
Resource path prefix that specifies to load from a classpath location, value is
classpath:
|
static String |
FILE_PREFIX
Resource path prefix that specifies to load from a file location, value is
file:
|
static String |
URL_PREFIX
Resource path prefix that specifies to load from a url location, value is
url:
|
| Modifier and Type | Method and Description |
|---|---|
static void |
close(InputStream
Convenience method that closes the specified
InputStream, logging any
IOException that might occur.
|
static InputStream |
getInputStreamForPath(String
Returns the InputStream for the resource represented by the specified path, supporting scheme prefixes that direct how to acquire the input stream (
CLASSPATH_PREFIX,
URL_PREFIX, or
FILE_PREFIX).
|
static boolean |
hasResourcePrefix(String
Returns
true if the resource path is not null and starts with one of the recognized resource prefixes (
CLASSPATH_PREFIX,
URL_PREFIX, or
FILE_PREFIX),
false otherwise.
|
static boolean |
resourceExists(String
Returns
true if the resource at the specified path exists,
false otherwise.
|
public static final StringCLASSPATH_PREFIX
classpath:
public static final StringURL_PREFIX
url:
public static final StringFILE_PREFIX
file:
public static boolean hasResourcePrefix(StringresourcePath)
true if the resource path is not null and starts with one of the recognized resource prefixes (
CLASSPATH_PREFIX,
URL_PREFIX, or
FILE_PREFIX),
false otherwise.
resourcePath - the resource path to check
true if the resource path is not null and starts with one of the recognized resource prefixes,
false otherwise.
public static boolean resourceExists(StringresourcePath)
true if the resource at the specified path exists,
false otherwise. This method supports scheme prefixes on the path as defined in
getInputStreamForPath(String).
resourcePath - the path of the resource to check.
true if the resource at the specified path exists,
false otherwise.
public static InputStreamgetInputStreamForPath(String resourcePath) throws IOException
CLASSPATH_PREFIX,
URL_PREFIX, or
FILE_PREFIX). If the path is not prefixed by one of these schemes, the path is assumed to be a file-based path that can be loaded with a
FileInputStream.
resourcePath - the String path representing the resource to obtain.
IOException - if there is a problem acquiring the resource at the specified path.
public static void close(InputStreamis)
InputStream, logging any
IOException that might occur. If the
InputStream argument is
null, this method does nothing. It returns quietly in all cases.
is - the
InputStream to close, logging any
IOException that might occur.