Class FileSystemResourceProvider

java.lang.Object
com.helger.io.resourceprovider.FileSystemResourceProvider
All Implemented Interfaces:
IReadableResourceProvider, IWritableResourceProvider

@ThreadSafe public class FileSystemResourceProvider extends Object implements IWritableResourceProvider
Simple resource provider that only uses files.
Author:
Philip Helger
  • Constructor Details

    • FileSystemResourceProvider

      public FileSystemResourceProvider()
      Constructor without a base path.
    • FileSystemResourceProvider

      public FileSystemResourceProvider(@NonNull String sBasePath)
      Constructor with a base path string.
      Parameters:
      sBasePath - The base path to use. May not be null. Must be an existing directory.
    • FileSystemResourceProvider

      public FileSystemResourceProvider(@Nullable File aBasePath)
      Constructor with a base path file.
      Parameters:
      aBasePath - The base path to use. May be null. If provided, must be an existing directory.
  • Method Details

    • getBasePath

      public final @Nullable File getBasePath()
      Returns:
      The base path as provided in the constructor. May be null.
    • isCanReadRelativePaths

      public final boolean isCanReadRelativePaths()
      Returns:
      true if relative paths can be read, false if only absolute paths are supported.
    • setCanReadRelativePaths

      public final @NonNull FileSystemResourceProvider setCanReadRelativePaths(boolean bCanReadRelativePaths)
      Enable or disable reading of relative paths.
      Parameters:
      bCanReadRelativePaths - true to enable relative path reading, false to restrict to absolute paths.
      Returns:
      this for chaining
    • supportsReading

      public boolean supportsReading(@Nullable String sName)
      Check if this resource provider can handle the resource with the passed name. If there is no real check on whether your resource provider can handle it, simply return true.
      Specified by:
      supportsReading in interface IReadableResourceProvider
      Parameters:
      sName - The name to check. May be null.
      Returns:
      true if the name is not null and can be handled by this provider, false otherwise.
    • supportsWriting

      public boolean supportsWriting(@Nullable String sName)
      Check if this resource provider can handle the resource with the passed name. If there is no real check on whether your resource provider can handle it, simply return true.
      Specified by:
      supportsWriting in interface IWritableResourceProvider
      Parameters:
      sName - The name to check. May be null.
      Returns:
      true if the name is not null and can be handled by this provider, false otherwise.
    • getReadableResource

      public @NonNull IReadableResource getReadableResource(@NonNull String sName)
      Get the resource specified by the given name for reading.
      Specified by:
      getReadableResource in interface IReadableResourceProvider
      Parameters:
      sName - The name of the resource to resolve.
      Returns:
      The readable resource. Never null.
    • getWritableResource

      public @NonNull IWritableResource getWritableResource(@NonNull String sName)
      Get the resource specified by the given name for writing.
      Specified by:
      getWritableResource in interface IWritableResourceProvider
      Parameters:
      sName - The name of the resource to resolve.
      Returns:
      The writable resource. Never null.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object