Class Resources

java.lang.Object
com.github.ngoanh2n.Resources

public final class Resources extends Object
Find and read Java resources.
  • Field Details

    • findOnClasspath

      public static final Property<Boolean> findOnClasspath
      Indicate to find the resource file on classpath.
      Default to true.
      • true: Look for the resources on the classpath.
        [PROJECT]/out/test/resources/ or [PROJECT]/out/production/resources/
      • false: Look for the resources in root location.
        [PROJECT]/src/test/resources/ or [PROJECT]/main/test/resources/
  • Method Details

    • getFile

      public static File getFile(@Nonnull String resourceName)
      Get the resource file.
      Parameters:
      resourceName - is the name of resource.
      e.g. com/foo/File.properties
      Returns:
      File of resource if the file exists; RuntimeError otherwise.
    • getPath

      public static Path getPath(@Nonnull String resourceName)
      Get the path of resource.
      Parameters:
      resourceName - is the name of resource.
      e.g. com/foo/File.properties
      Returns:
      Path of resource if the file exists; RuntimeError otherwise.
    • getInputStream

      public static InputStream getInputStream(@Nonnull String resourceName)
      Get the resource file as InputStream.
      Parameters:
      resourceName - is the name of resource.
      e.g. com/foo/File.properties
      Returns:
      InputStream if the file exists; RuntimeError otherwise.
    • getContent

      public static String getContent(@Nonnull String resourceName)
      Get the resource file as String.
      Parameters:
      resourceName - is the name of resource.
      e.g. com/foo/File.properties
      Returns:
      String if the file exists; RuntimeError otherwise.
    • getContent

      public static String getContent(@Nonnull String resourceName, @Nonnull Charset charset)
      Get the resource file as String.
      Parameters:
      resourceName - is the name of resource.
      e.g. com/foo/File.properties
      charset - the charset to use, null means platform default.
      Returns:
      String if the file exists; RuntimeError otherwise.