Object ResourceLoader
-
- All Implemented Interfaces:
public class ResourceLoaderThe ResourceLoader class is a utility class to load resources from the classpath.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceResourceLoader.ClassFactoryThe utility methods will try to use the provided class factories to convert binary name of class to Class object. Used by H2 OSGi Activator in order to provide a class from another bundle ClassLoader.
-
Field Summary
Fields Modifier and Type Field Description public final static ResourceLoaderINSTANCE
-
Method Summary
Modifier and Type Method Description final UnitaddClassFactory(ResourceLoader.ClassFactory classFactory)Add a class factory in order to manage more than one class loader. final UnitremoveClassFactory(ResourceLoader.ClassFactory classFactory)Remove a class factory final <Z extends Any> Class<Z>loadUserClass(String className)Load a class, but check if it is allowed to load this class first. final List<String>readAllLines(String stringResource, String resource, String resourcePrefix, Boolean filter)Read all lines from one of the following resource: string, file by file name and resource by resource name The front resource have higher priority final List<String>readAllLines(String stringResource, String resource, String resourcePrefix)Read all lines from one of the following resource: string, file by file name and resource by resource name The front resource have higher priority final List<String>readAllLines(String stringResource, String resource)Read all lines from one of the following resource: string, file by file name and resource by resource name The front resource have higher priority final List<String>readAllLines(String resource)final List<String>readAllLines(String resource, Boolean filter)final List<String>readAllLines(String resource, Function1<String, Boolean> filter)final List<String>readAllLinesNoFilter(String resource)final List<String>readAllLinesIfModified(Path path)final StringreadString(String resource)final StringBuilderreadStringTo(String resource, StringBuilder sb)final InputStreamgetResourceAsStream(String name)Get a Reader attached to the configuration resource with the given name.final InputStreamgetResourceAsStream(String resource, String resourcePrefixes)Find the first resource associated by prefix/name final ReadergetResourceAsReader(String resource, String resourcePrefixes)Get a Reader attached to the configuration resource with the given name.final Booleanexists(String name)Check if a resource exists final URLgetURLOrNull(String name)Finds a resource with a given name. final <T extends Any> URLgetURLOrNull(String name, Class<T> preferredClassLoader)Finds a resource with a given name. final URLgetURL(String name)Finds a resource with a given name. final <T extends Any> URLgetURL(String name, Class<T> preferredClassLoader)Finds a resource with a given name. final PathgetPath(String resource)Finds a resource with a given name. final PathgetPathOrNull(String resource)Finds a resource with a given name. final ReadergetMultiSourceReader(String stringResource, String resource)final ReadergetMultiSourceReader(String stringResource, String namedResource, String resourcePrefix)-
-
Method Detail
-
addClassFactory
final Unit addClassFactory(ResourceLoader.ClassFactory classFactory)
Add a class factory in order to manage more than one class loader.
- Parameters:
classFactory- An object that implements ClassFactory
-
removeClassFactory
final Unit removeClassFactory(ResourceLoader.ClassFactory classFactory)
Remove a class factory
- Parameters:
classFactory- Already inserted class factory instance
-
loadUserClass
final <Z extends Any> Class<Z> loadUserClass(String className)
Load a class, but check if it is allowed to load this class first. To perform access rights checking, the system property h2.allowedClasses needs to be set to a list of class file name prefixes.
- Parameters:
className- the name of the class- Returns:
the class object
-
readAllLines
@JvmOverloads() final List<String> readAllLines(String stringResource, String resource, String resourcePrefix, Boolean filter)
Read all lines from one of the following resource: string, file by file name and resource by resource name The front resource have higher priority
-
readAllLines
@JvmOverloads() final List<String> readAllLines(String stringResource, String resource, String resourcePrefix)
Read all lines from one of the following resource: string, file by file name and resource by resource name The front resource have higher priority
-
readAllLines
@JvmOverloads() final List<String> readAllLines(String stringResource, String resource)
Read all lines from one of the following resource: string, file by file name and resource by resource name The front resource have higher priority
-
readAllLines
final List<String> readAllLines(String resource)
-
readAllLines
final List<String> readAllLines(String resource, Boolean filter)
-
readAllLinesNoFilter
final List<String> readAllLinesNoFilter(String resource)
-
readAllLinesIfModified
final List<String> readAllLinesIfModified(Path path)
-
readString
final String readString(String resource)
-
readStringTo
final StringBuilder readStringTo(String resource, StringBuilder sb)
-
getResourceAsStream
final InputStream getResourceAsStream(String name)
Get a Reader attached to the configuration resource with the given
name.- Parameters:
name- resource name.- Returns:
a reader attached to the resource.
-
getResourceAsStream
final InputStream getResourceAsStream(String resource, String resourcePrefixes)
Find the first resource associated by prefix/name
-
getResourceAsReader
final Reader getResourceAsReader(String resource, String resourcePrefixes)
Get a Reader attached to the configuration resource with the given
name.- Parameters:
resource- configuration resource name.- Returns:
a reader attached to the resource.
-
getURLOrNull
final URL getURLOrNull(String name)
Finds a resource with a given name.
Find resources first by each registered class loader and then by the default class loader.
- Parameters:
name- name of the desired resource- Returns:
URL object for reading the resource; null if the resource could not be found
-
getURLOrNull
final <T extends Any> URL getURLOrNull(String name, Class<T> preferredClassLoader)
Finds a resource with a given name.
- Parameters:
name- resource name.preferredClassLoader- preferred class loader, this class loader is used first, fallback to other class loaders if the resource not found by preferred class loader.- Returns:
URL object for reading the resource; null if the resource could not be found
-
getURL
final URL getURL(String name)
Finds a resource with a given name.
- Parameters:
name- resource name.- Returns:
the url for the named resource.
-
getURL
final <T extends Any> URL getURL(String name, Class<T> preferredClassLoader)
Finds a resource with a given name.
- Parameters:
name- resource name.preferredClassLoader- preferred class loader, this class loader is used first, fallback to other class loaders if the resource not found by preferred class loader.- Returns:
the url for the named resource.
-
getPath
final Path getPath(String resource)
Finds a resource with a given name.
- Parameters:
resource- resource name.- Returns:
the path for the named resource.
-
getPathOrNull
final Path getPathOrNull(String resource)
Finds a resource with a given name.
- Parameters:
resource- resource name.- Returns:
the path for the named resource.
-
getMultiSourceReader
final Reader getMultiSourceReader(String stringResource, String resource)
-
getMultiSourceReader
final Reader getMultiSourceReader(String stringResource, String namedResource, String resourcePrefix)
-
-
-
-