Package org.cloudbus.cloudsim.util
Class ResourceLoader
java.lang.Object
org.cloudbus.cloudsim.util.ResourceLoader
public final class ResourceLoader extends 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 List<String>
getResourceList(Class klass, String resourceDir)
Gets the list of files contained inside a given resource directory.static String
getResourcePath(Class klass, String name)
Gets the absolute path of a resource (a file or sub-directory) inside the resources directory.static URL
getResourceUrl(Class klass, String name)
Gets theURL
of a resource (a file or sub-directory) inside the resources directory.static BufferedReader
newBufferedReader(String filePath, Class klass)
Instantiates aBufferedReader
to read a file (a file or sub-directory inside the resources directory) from its path.static InputStream
newInputStream(String filePath, Class klass)
Instantiates aInputStream
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 InputStreamReader
newInputStreamReader(String filePath)
Instantiates aInputStreamReader
to read a file outside the resource directory.static InputStreamReader
newInputStreamReader(String filePath, Class klass)
Instantiates aInputStreamReader
to read a file, trying to load the file from a jar file, in case the user is running simulations from a jar package.
-
Method Details
-
newBufferedReader
Instantiates aBufferedReader
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 aBufferedReader
for itklass
- 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
Instantiates aInputStreamReader
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 itklass
- 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)
-
newInputStream
Instantiates aInputStream
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 itklass
- 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
Instantiates aInputStreamReader
to read a file outside the resource directory.- Parameters:
filePath
- the path to the file- Returns:
- a
InputStreamReader
to read the resource - Throws:
FileNotFoundException
- when the file doesn't exist
-
getResourcePath
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 directoryname
- 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
Gets theURL
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 directoryname
- 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
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 directoryresourceDir
- the name of the resource directory to get the list of files from- Returns:
-