Class DefaultClassPathResourceLoader

java.lang.Object
io.micronaut.core.io.scan.DefaultClassPathResourceLoader
All Implemented Interfaces:
ResourceLoader, ClassPathResourceLoader

public class DefaultClassPathResourceLoader extends Object implements ClassPathResourceLoader
Loads resources from the classpath.
Since:
1.0
Author:
James Kleeh, graemerocher
  • Constructor Details

    • DefaultClassPathResourceLoader

      public DefaultClassPathResourceLoader(ClassLoader classLoader)
      Default constructor.
      Parameters:
      classLoader - The class loader for loading resources
    • DefaultClassPathResourceLoader

      public DefaultClassPathResourceLoader(ClassLoader classLoader, String basePath)
      Use when resources should have a standard base path.
      Parameters:
      classLoader - The class loader for loading resources
      basePath - The path to look for resources under
    • DefaultClassPathResourceLoader

      public DefaultClassPathResourceLoader(ClassLoader classLoader, String basePath, boolean checkBase)
      Use when resources should have a standard base path.
      Parameters:
      classLoader - The class loader for loading resources
      basePath - The path to look for resources under
      checkBase - If set to true an extended check for the base path is performed otherwise paths with relative URLs like ../ are prohibited.
    • DefaultClassPathResourceLoader

      public DefaultClassPathResourceLoader(ClassLoader classLoader, String basePath, boolean checkBase, boolean logEnabled)
      Use when resources should have a standard base path.
      Parameters:
      classLoader - The class loader for loading resources
      basePath - The path to look for resources under
      checkBase - If set to true 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 Details

    • getResourceAsStream

      public Optional<InputStream> getResourceAsStream(String path)
      Obtains a resource as a stream.
      Specified by:
      getResourceAsStream in interface ResourceLoader
      Parameters:
      path - The path
      Returns:
      An optional resource
    • getResource

      public Optional<URL> getResource(String path)
      Obtains a resource URL.
      Specified by:
      getResource in interface ResourceLoader
      Parameters:
      path - The path
      Returns:
      An optional resource
    • getResources

      public Stream<URL> getResources(String path)
      Obtains a stream of resource URLs.
      Specified by:
      getResources in interface ResourceLoader
      Parameters:
      path - The path
      Returns:
      A resource stream
    • getClassLoader

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface ClassPathResourceLoader
      Returns:
      The class loader used to retrieve resources
    • forBase

      public ResourceLoader forBase(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 interface ResourceLoader
      Parameters:
      basePath - The path to load resources
      Returns:
      The resource loader
    • forBase

      public ResourceLoader forBase(String basePath, boolean logEnabled)
      Need this method to ability disable Slf4J initizalization.
      Parameters:
      basePath - The path to load resources
      logEnabled - flag to enable or disable logger
      Returns:
      The resource loader