public class ResourceLoader
extends java.lang.Object
Constructor | Description |
---|---|
ResourceLoader() |
Modifier and Type | Method | Description |
---|---|---|
static java.io.InputStream |
getResource(java.lang.String location,
java.lang.Object target) |
Locates the requested resource and returns an open
InputStream if the requested resource could be
located, otherwise an exception will be thrown. |
static java.io.InputStream |
getResource(java.net.URI uri,
java.lang.Object target) |
Locates the requested resource and returns an open
InputStream if the requested resource could be
located, otherwise an exception will be thrown. |
static java.io.InputStream |
getResourceFromLocations(java.lang.String filename,
java.lang.Object target,
java.lang.String... locations) |
Tries to open an input stream for the given file name by trying to open the stream from the given locations one
after another.
|
public static java.io.InputStream getResource(java.lang.String location, java.lang.Object target) throws java.net.URISyntaxException, java.io.IOException
InputStream
if the requested resource could be
located, otherwise an exception will be thrown. See ResourceLoader
for supported URI schemes.location
- Location as URI of the resource/file.target
- The object which will use the resource, this is only important when the URI
scheme is "classpath" as the class loader of the given class will be used
in order to find the resource.java.io.FileNotFoundException
- If the file could not be found.java.net.URISyntaxException
- The syntax of the given URI is invalid.java.net.MalformedURLException
- The URL in the case the scheme is http is invalid.java.io.IOException
- Any other exception that can happen during opening a resource.public static java.io.InputStream getResource(java.net.URI uri, java.lang.Object target) throws java.net.URISyntaxException, java.io.IOException
InputStream
if the requested resource could be
located, otherwise an exception will be thrown. See ResourceLoader
for supported URI schemes.uri
- Location of the resource/file.target
- The object which will use the resource, this is only important when the URI
scheme is "classpath" as the class loader of the given class will be used
in order to find the resource.java.io.FileNotFoundException
- If the file could not be found.java.net.URISyntaxException
- The syntax of the given URI is invalid.java.net.MalformedURLException
- The URL in the case the scheme is http is invalid.java.io.IOException
- Any other exception that can happen during opening a resource.public static java.io.InputStream getResourceFromLocations(java.lang.String filename, java.lang.Object target, java.lang.String... locations) throws java.io.FileNotFoundException
ResourceLoader
for supported URI schemes.filename
- File name of the resource to open.target
- The object which will use the resource, this is only important when the URI
scheme is "classpath" as the class loader of the given class will be used
in order to find the resource.locations
- All the locations as URIs to search for.java.io.FileNotFoundException
- If the file could not be found in any of the given locations.