Class ResourceHelper
java.lang.Object
org.sentrysoftware.metricshub.engine.common.helpers.ResourceHelper
Helper class for working with resources.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilefindSourceDirectory(@NonNull Class<?> sourceClass) Retrieves the directory containing the given source class, whether it's located within a JAR file or a regular directory.static StringgetResourceAsString(String path, @NonNull Class<?> clazz) Get resource file content as String for the given class.
-
Constructor Details
-
ResourceHelper
public ResourceHelper()
-
-
Method Details
-
getResourceAsString
Get resource file content as String for the given class.- Parameters:
path- path of the file in the resources directoryclazz- class used to load the resource as stream- Returns:
- Resource file as
String
-
findSourceDirectory
public static File findSourceDirectory(@NonNull @NonNull Class<?> sourceClass) throws IOException, URISyntaxException Retrieves the directory containing the given source class, whether it's located within a JAR file or a regular directory.- Parameters:
sourceClass- The sourceClass we wish to get its directory, this class could be located under a JAR or a regular folder such as \target\classes- Returns:
Fileinstance representing the source directory.- Throws:
IOException- If theURLConnectioncannot be opened or an error occurs while trying to connect to the JAR file using theJarURLConnectionURISyntaxException- If theURLConnectionis not formatted strictly according to RFC2396 and cannot be converted to a URI.
-