Class ResourceLoader

java.lang.Object
org.cloudbus.cloudsim.util.ResourceLoader

public final class ResourceLoader extends Object
A utility class that loads a resource file/directory that is contained inside the directory of a given class.
Author:
Manoel Campos da Silva Filho
  • Method Details

    • newBufferedReader

      public static BufferedReader newBufferedReader(String filePath, Class klass)
      Instantiates a BufferedReader to read a file (a file or sub-directory inside the resources directory) from its path.
      Parameters:
      filePath - the path of the resource to get a BufferedReader for it
      klass - a class from the project that will be used just to assist in getting the path of the given resource
      Returns:
      a BufferedReader to read the resource
      Throws:
      FileNotFoundException - when the file doesn't exist
    • newInputStreamReader

      public static InputStreamReader newInputStreamReader(String filePath, Class klass)
      Instantiates a InputStreamReader to read a file, trying to load the file from a jar file, in case the user is running simulations from a jar package. If it cant get a reader directly, the simulation is not being executed from a jar package, so try to load the file from a directory in the filesystem.
      Parameters:
      filePath - the path of the file to get a reader for it
      klass - a class from the project that will be used just to assist in getting the path of the given resource
      Returns:
      a InputStreamReader to read the resource
      Throws:
      UncheckedIOException - when the file cannot be accessed (such as when it doesn't exist)
    • newInputStreamReader

      public static InputStreamReader newInputStreamReader(String filePath)
      Instantiates a InputStreamReader to read a file outside the resource directory.
      Parameters:
      filePath - the path to the file
      Returns:
      a InputStreamReader to read the resource
      Throws:
      UncheckedIOException - when the file doesn't exist or can't be accessed
    • newInputStream

      public static InputStream newInputStream(String filePath, Class klass)
      Instantiates a InputStream to read a file, trying to load the file from a jar file, in case the user is running simulations from a jar package. If it can't get a reader directly, the simulation is not being executed from a jar package, so try to load the file from a directory in the filesystem.
      Parameters:
      filePath - the path of the file to get a reader for it
      klass - a class from the project that will be used just to assist in getting the path of the given resource
      Returns:
      a InputStreamReader to read the resource
      Throws:
      UncheckedIOException - when the file doesn't exist or can't be accessed
    • getResourcePath

      public static String getResourcePath(Class klass, String name)
      Gets the absolute path of a resource (a file or sub-directory) inside the resources directory.
      Parameters:
      klass - a class from the project which will be used just to assist in getting the path of the given resource. It can can any class inside the project where a resource you are trying to get from the resources directory
      name - the name of the resource to get its path (that can be a file or a sub-directory inside the resources directory)
      Returns:
      the absolute path of the resource
    • getResourceUrl

      public static URL getResourceUrl(Class klass, String name)
      Gets the URL of a resource (a file or sub-directory) inside the resources directory.
      Parameters:
      klass - a class from the project which will be used just to assist in getting the path of the given resource. It can can any class inside the project where a resource you are trying to get from the resources directory
      name - the name of the resource to get its path (that can be a file or a sub-directory inside the resources directory)
      Returns:
      the URL of the resource
    • getResourceList

      public static List<String> getResourceList(Class klass, String resourceDir)
      Gets the list of files contained inside a given resource directory.
      Parameters:
      klass - a class from the project which will be used just to assist in getting the path of the given resource. It can can any class inside the project where a resource you are trying to get from the resources directory
      resourceDir - the name of the resource directory to get the list of files from
      Returns: