java.lang.Object
org.sentrysoftware.metricshub.engine.common.helpers.ResourceHelper

public class ResourceHelper extends Object
Helper class for working with resources.
  • Constructor Details

    • ResourceHelper

      public ResourceHelper()
  • Method Details

    • getResourceAsString

      public static String getResourceAsString(String path, @NonNull @NonNull Class<?> clazz)
      Get resource file content as String for the given class.
      Parameters:
      path - path of the file in the resources directory
      clazz - 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:
      File instance representing the source directory.
      Throws:
      IOException - If the URLConnection cannot be opened or an error occurs while trying to connect to the JAR file using the JarURLConnection
      URISyntaxException - If the URLConnection is not formatted strictly according to RFC2396 and cannot be converted to a URI.