public final class UrlResourceUtil extends Object
This utility can be used to allow consumers the same interface to load resources from classpaths, file system, HTTP, etc. This class is inspired by the Spring Framework DefaultResourceLoader.
Supported formats or URLs by this util:
classpath:/org/deventropy/junithelper/utils/file.ext
file:/path/to/file/file.ext
http://example.com/file.ext
https://example.com/file.ext
Modifier and Type | Field and Description |
---|---|
static Set<String> |
KNOWN_PROTOCOLS
known protocols.
|
static String |
URL_PROTOCOL_CLASSPATH
Classpath URL prefix.
|
static String |
URL_PROTOCOL_FILE
File url prefix.
|
static String |
URL_PROTOCOL_HTTP
HTTP url prefix.
|
static String |
URL_PROTOCOL_HTTPS
HTTPS url prefix.
|
Modifier and Type | Method and Description |
---|---|
static File |
getFileForWrite(String resource) |
static URL |
getUrl(String resource) |
static URL |
getUrl(String resource,
ClassLoader cl) |
static boolean |
isFile(String resource) |
public static final String URL_PROTOCOL_CLASSPATH
public static final String URL_PROTOCOL_FILE
public static final String URL_PROTOCOL_HTTP
public static final String URL_PROTOCOL_HTTPS
public static URL getUrl(String resource, ClassLoader cl) throws MalformedURLException, IOException
resource
- Resource to checklcl
- Classpath to useMalformedURLException
- Malformed URLIOException
- Resource not foundpublic static URL getUrl(String resource) throws IOException
resource
- Resource to checkIOException
- Exception getting the URLpublic static boolean isFile(String resource)
resource
- If the resource is a filetrue
if file on mounted drivepublic static File getFileForWrite(String resource) throws IOException
resource
- OPen resource as a file to writeIOException
- Exception trying to open a fileCopyright © 2016-2016 Development Entropy (deventropy.org) Contributors