Class ResourceLoader

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

public final class ResourceLoader
extends java.lang.Object
An 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 Summary

    Modifier and Type Method Description
    static java.util.List<java.lang.String> getResourceList​(java.lang.Class klass, java.lang.String resourceDir)
    Gets the list of files contained inside a given resource directory.
    static java.lang.String getResourcePath​(java.lang.Class klass, java.lang.String name)
    Gets the absolute path of a resource (a file or sub-directory) inside the resources directory.
    static java.net.URL getResourceUrl​(java.lang.Class klass, java.lang.String name)
    Gets the URL of a resource (a file or sub-directory) inside the resources directory.
    static java.io.BufferedReader newBufferedReader​(java.lang.String filePath, java.lang.Class klass)
    Instantiates a BufferedReader to read a file (a file or sub-directory inside the resources directory) from its path.
    static java.io.InputStream newInputStream​(java.lang.String filePath, java.lang.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.
    static java.io.InputStreamReader newInputStreamReader​(java.lang.String filePath)
    Instantiates a InputStreamReader to read a file outside the resource directory.
    static java.io.InputStreamReader newInputStreamReader​(java.lang.String filePath, java.lang.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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • newBufferedReader

      public static java.io.BufferedReader newBufferedReader​(java.lang.String filePath, java.lang.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:
      java.io.FileNotFoundException - when the file doesn't exist
    • newInputStreamReader

      public static java.io.InputStreamReader newInputStreamReader​(java.lang.String filePath, java.lang.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:
      java.io.UncheckedIOException - when the file cannot be accessed (such as when it doesn't exist)
    • newInputStream

      public static java.io.InputStream newInputStream​(java.lang.String filePath, java.lang.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 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:
      java.io.UncheckedIOException - when the file cannot be accessed (such as when it doesn't exist)
    • newInputStreamReader

      public static java.io.InputStreamReader newInputStreamReader​(java.lang.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:
      java.io.FileNotFoundException - when the file doesn't exist
    • getResourcePath

      public static java.lang.String getResourcePath​(java.lang.Class klass, java.lang.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 java.net.URL getResourceUrl​(java.lang.Class klass, java.lang.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 java.util.List<java.lang.String> getResourceList​(java.lang.Class klass, java.lang.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: