ResourceLoader

public final class ResourceLoader

Loads a resource file/directory that is contained inside the directory of a given class.

Author:Manoel Campos da Silva Filho

Methods

getBufferedReader

public static BufferedReader getBufferedReader(Class klass, String resourceName)

Gets a BufferedReader to read a resource (a file or sub-directory inside the resources directory) from its absolute path.

Parameters:
  • klass – a class from the project that will be used just to assist in getting the path of the given resource
  • resourceName – the name of the resource to get a BufferedReader for it
Throws:
  • FileNotFoundException – when the file doesn’t exist
Returns:

a BufferedReader to read the resource

getFileReader

public static FileReader getFileReader(String filePath)

Gets a FileReader

Parameters:
  • filePath – the path to the file
Returns:

the FileReader instance.

getInputStream

public static InputStream getInputStream(Class klass, String resourceName)

Try to load the resource from a jar file, in case the user is running simulations from a jar instead of directly from the IDE. If the input is null, the simulation is not being executed from a jar file, so try to load the resource from a directory in the filesystem.

Parameters:
  • klass – a class from the project that will be used just to assist in getting the path of the given resource
  • resourceName – the name of the resource to get a BufferedReader for it
Throws:
  • UncheckedIOException – when the file cannot be accessed (such as when it doesn’t exist)
Returns:

a InputStream to read 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

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