Class ResourceUtil

java.lang.Object
com.helixframework.file.ResourceUtil

public class ResourceUtil extends Object
Utility for working with classpath resources.
  • Method Details

    • doesResourceExist

      public static boolean doesResourceExist(String relativePath)
      Checks to see if the resource exists.
      Parameters:
      relativePath - resource path
      Returns:
      true if the resource exists; otherwise false
    • doesResourceExist

      public static boolean doesResourceExist(String relativePath, Class<?> relativeClass)
      Checks to see if the resource exists.
      Parameters:
      relativePath - resource path
      relativeClass - class that should be used for determining the correct classloader
      Returns:
      true if the resource exists; otherwise false
    • getResourceAsStream

      public static InputStream getResourceAsStream(String relativePath) throws IOException
      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 path
      relativeClass - class that should be used for determining the correct classloader
      Returns:
      the resource as an InputStream
      Throws:
      IOException - if unable to load resource
    • getResourceAsString

      public static String getResourceAsString(String relativePath) throws IOException
      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 path
      relativeClass - class that should be used for determining the correct classloader
      Returns:
      the resource as a string
      Throws:
      IOException - if unable to load resource
    • getResourceAsFile

      public static File getResourceAsFile(String relativePath) throws IOException
      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 path
      relativeClass - class that should be used for determining the correct classloader
      Returns:
      the resource as a File
      Throws:
      IOException - if unable to load resource
    • getJsonResourceAs

      public static <T> T getJsonResourceAs(String relativePath, Class<T> type) throws IOException
      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 path
      type - 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 path
      relativeClass - class that should be used for determining the correct classloader
      type - 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 path
      relativeClass - class that should be used for determining the correct classloader
      Returns:
      the resource as a JsonNode
      Throws:
      IOException - if unable to load resource