Package io.micronaut.core.io.scan
Class DefaultClassPathResourceLoader
- java.lang.Object
-
- io.micronaut.core.io.scan.DefaultClassPathResourceLoader
-
- All Implemented Interfaces:
ResourceLoader
,ClassPathResourceLoader
public class DefaultClassPathResourceLoader extends java.lang.Object implements ClassPathResourceLoader
Loads resources from the classpath.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader)
Default constructor.DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader, java.lang.String basePath)
Use when resources should have a standard base path.DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader, java.lang.String basePath, boolean checkBase)
Use when resources should have a standard base path.DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader, java.lang.String basePath, boolean checkBase, boolean logEnabled)
Use when resources should have a standard base path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourceLoader
forBase(java.lang.String basePath)
Constructs a new resource loader designed to load resources from the given path.ResourceLoader
forBase(java.lang.String basePath, boolean logEnabled)
Need this method to ability disable Slf4J initizalization.java.lang.ClassLoader
getClassLoader()
java.util.Optional<java.net.URL>
getResource(java.lang.String path)
Obtains a resource URL.java.util.Optional<java.io.InputStream>
getResourceAsStream(java.lang.String path)
Obtains a resource as a stream.java.util.stream.Stream<java.net.URL>
getResources(java.lang.String path)
Obtains a stream of resource URLs.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.core.io.scan.ClassPathResourceLoader
supportsPrefix
-
-
-
-
Constructor Detail
-
DefaultClassPathResourceLoader
public DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader)
Default constructor.- Parameters:
classLoader
- The class loader for loading resources
-
DefaultClassPathResourceLoader
public DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader, java.lang.String basePath)
Use when resources should have a standard base path.- Parameters:
classLoader
- The class loader for loading resourcesbasePath
- The path to look for resources under
-
DefaultClassPathResourceLoader
public DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader, java.lang.String basePath, boolean checkBase)
Use when resources should have a standard base path.- Parameters:
classLoader
- The class loader for loading resourcesbasePath
- The path to look for resources undercheckBase
- If set totrue
an extended check for the base path is performed otherwise paths with relative URLs like../
are prohibited.
-
DefaultClassPathResourceLoader
public DefaultClassPathResourceLoader(java.lang.ClassLoader classLoader, java.lang.String basePath, boolean checkBase, boolean logEnabled)
Use when resources should have a standard base path.- Parameters:
classLoader
- The class loader for loading resourcesbasePath
- The path to look for resources undercheckBase
- If set totrue
an extended check for the base path is performed otherwise paths with relative URLs like../
are prohibited.logEnabled
- flag to enable or disable logger
-
-
Method Detail
-
getResourceAsStream
public java.util.Optional<java.io.InputStream> getResourceAsStream(java.lang.String path)
Obtains a resource as a stream.- Specified by:
getResourceAsStream
in interfaceResourceLoader
- Parameters:
path
- The path- Returns:
- An optional resource
-
getResource
public java.util.Optional<java.net.URL> getResource(java.lang.String path)
Obtains a resource URL.- Specified by:
getResource
in interfaceResourceLoader
- Parameters:
path
- The path- Returns:
- An optional resource
-
getResources
public java.util.stream.Stream<java.net.URL> getResources(java.lang.String path)
Obtains a stream of resource URLs.- Specified by:
getResources
in interfaceResourceLoader
- Parameters:
path
- The path- Returns:
- A resource stream
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
- Specified by:
getClassLoader
in interfaceClassPathResourceLoader
- Returns:
- The class loader used to retrieve resources
-
forBase
public ResourceLoader forBase(java.lang.String basePath)
Description copied from interface:ResourceLoader
Constructs a new resource loader designed to load resources from the given path. Requested resources will be loaded within the context of the given path.- Specified by:
forBase
in interfaceResourceLoader
- Parameters:
basePath
- The path to load resources- Returns:
- The resource loader
-
forBase
public ResourceLoader forBase(java.lang.String basePath, boolean logEnabled)
Need this method to ability disable Slf4J initizalization.- Parameters:
basePath
- The path to load resourceslogEnabled
- flag to enable or disable logger- Returns:
- The resource loader
-
-