Class ResourcesUtil

java.lang.Object
org.gbif.utils.file.ResourcesUtil

public final class ResourcesUtil extends Object
Utils class dealing with classpath resources.
  • Method Details

    • copy

      public static void copy(File folder, String classpathPrefix, boolean ignoreMissingResources, String... classpathResources) throws IOException
      Copies classpath resources to real files.
      Parameters:
      folder - to copy resource files into
      ignoreMissingResources - if true ignores missing resources, throws IOException otherwise
      classpathPrefix - common prefix added to all classpath resources which is not used for the result file path.
      classpathResources - list of classpath resources to be copied into folder
      Throws:
      IOException
    • getResource

      public static URL getResource(String resourceName)
      Returns a URL pointing to resourceName if the resource is found using the context class loader. In simple environments, the context class loader will find resources from the class path. In environments where different threads can have different class loaders, for example app servers, the context class loader will typically have been set to an appropriate loader for the current thread.

      In the unusual case where the context class loader is null, the class loader that loaded this class will be used instead.

      From Guava.

      Throws:
      IllegalArgumentException - if the resource is not found
    • list

      public static String[] list(Class clazz, String path) throws IOException
      List directory contents for a resource folder. Not recursive. Works for regular files and also JARs. Based on code from Greg Briggs, slightly modified.
      Parameters:
      clazz - Any java class that lives in the same place as the resources you want.
      path - Should end with "/", but not start with one.
      Returns:
      Just the name of each member item, not the full paths. Empty array in case folder cannot be found
      Throws:
      IOException