Package com.helixframework.file
Class ResourceUtil
java.lang.Object
com.helixframework.file.ResourceUtil
Utility for working with classpath resources.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleandoesResourceExist(String relativePath) Checks to see if the resource exists.static booleandoesResourceExist(String relativePath, Class<?> relativeClass) Checks to see if the resource exists.static <T> TgetJsonResourceAs(String relativePath, Class<?> relativeClass, Class<T> type) Gets the JSON resource, as a concrete type, off the classloader of the specified class.static <T> TgetJsonResourceAs(String relativePath, Class<T> type) Gets the JSON resource, as a concrete type, off the current classloader's classpath.static FilegetResourceAsFile(String relativePath) Gets the resource, as a File, off the current classloader's classpath.static FilegetResourceAsFile(String relativePath, Class<?> relativeClass) Gets the resource, as a File, off the classloader of the specified class.static com.fasterxml.jackson.databind.JsonNodegetResourceAsJsonNode(String relativePath) Gets the JSON resource, as a JsonNode, off the current classloader's classpath.static com.fasterxml.jackson.databind.JsonNodegetResourceAsJsonNode(String relativePath, Class<?> relativeClass) Gets the JSON resource, as a JsonNode, off the classloader of the specified class.static InputStreamgetResourceAsStream(String relativePath) Gets the resource off the current classloader's classpath.static InputStreamgetResourceAsStream(String relativePath, Class<?> relativeClass) Gets the resource off the classloader of the specified class.static StringgetResourceAsString(String relativePath) Gets the resource, as a string, off the current classloader's classpath.static StringgetResourceAsString(String relativePath, Class<?> relativeClass) Gets the resource, as a string, off the classloader of the specified class.
-
Method Details
-
doesResourceExist
Checks to see if the resource exists.- Parameters:
relativePath- resource path- Returns:
trueif the resource exists; otherwisefalse
-
doesResourceExist
Checks to see if the resource exists.- Parameters:
relativePath- resource pathrelativeClass- class that should be used for determining the correct classloader- Returns:
trueif the resource exists; otherwisefalse
-
getResourceAsStream
Gets the resource off the current classloader's classpath.- Parameters:
relativePath- resource path- Returns:
- the resource as an
InputStream - Throws:
IOException- if unable to load resource
-
getResourceAsStream
public static InputStream getResourceAsStream(String relativePath, Class<?> relativeClass) throws IOException Gets the resource off the classloader of the specified class.- Parameters:
relativePath- resource pathrelativeClass- class that should be used for determining the correct classloader- Returns:
- the resource as an
InputStream - Throws:
IOException- if unable to load resource
-
getResourceAsString
Gets the resource, as a string, off the current classloader's classpath.- Parameters:
relativePath- resource path- Returns:
- the resource as a string
- Throws:
IOException- if unable to load resource
-
getResourceAsString
public static String getResourceAsString(String relativePath, Class<?> relativeClass) throws IOException Gets the resource, as a string, off the classloader of the specified class.- Parameters:
relativePath- resource pathrelativeClass- class that should be used for determining the correct classloader- Returns:
- the resource as a string
- Throws:
IOException- if unable to load resource
-
getResourceAsFile
Gets the resource, as a File, off the current classloader's classpath.- Parameters:
relativePath- resource path- Returns:
- the resource as a File
- Throws:
IOException- if unable to load resource
-
getResourceAsFile
public static File getResourceAsFile(String relativePath, Class<?> relativeClass) throws IOException Gets the resource, as a File, off the classloader of the specified class.- Parameters:
relativePath- resource pathrelativeClass- class that should be used for determining the correct classloader- Returns:
- the resource as a File
- Throws:
IOException- if unable to load resource
-
getJsonResourceAs
Gets the JSON resource, as a concrete type, off the current classloader's classpath.- Type Parameters:
T- type of object to return- Parameters:
relativePath- resource pathtype- type of object to return- Returns:
- the resource cast to the specified object
- Throws:
IOException- if unable to load resource
-
getJsonResourceAs
public static <T> T getJsonResourceAs(String relativePath, Class<?> relativeClass, Class<T> type) throws IOException Gets the JSON resource, as a concrete type, off the classloader of the specified class.- Type Parameters:
T- type of object to return- Parameters:
relativePath- resource pathrelativeClass- class that should be used for determining the correct classloadertype- type of object to return- Returns:
- the resource cast to the specified object
- Throws:
IOException- if unable to load resource
-
getResourceAsJsonNode
public static com.fasterxml.jackson.databind.JsonNode getResourceAsJsonNode(String relativePath) throws IOException Gets the JSON resource, as a JsonNode, off the current classloader's classpath.- Parameters:
relativePath- resource path- Returns:
- the resource as a JsonNode
- Throws:
IOException- if unable to load resource
-
getResourceAsJsonNode
public static com.fasterxml.jackson.databind.JsonNode getResourceAsJsonNode(String relativePath, Class<?> relativeClass) throws IOException Gets the JSON resource, as a JsonNode, off the classloader of the specified class.- Parameters:
relativePath- resource pathrelativeClass- class that should be used for determining the correct classloader- Returns:
- the resource as a JsonNode
- Throws:
IOException- if unable to load resource
-