Class FlatFileResolver

  • All Implemented Interfaces:
    Closeable, AutoCloseable, PropertyResolver

    public class FlatFileResolver
    extends Object
    implements PropertyResolver, Closeable
    A PropertyResolver in which each property is stored in its own file in some directory. The entire contents of the file (as UTF-8) is returned as the value of the property. For efficiency and consistency with the other property resolvers, the contents of files are cached in-memory. Use the FlatFileResolver(Path, String, DirectoryWatcher) constructor to enable the cache to be updated when files change, otherwise files are cached permanently. A maximum size of 2MB is imposed on files, and any file larger than this will be ignored.
    • Constructor Detail

      • FlatFileResolver

        public FlatFileResolver​(Path rootDirectory,
                                String suffix)
        Initializes the resolver with the given root directory. Files are cached permanently after first access.
        Parameters:
        rootDirectory - the root directory to resolve files relative to.
        suffix - a suffix to append to property names such as a file extension, for instance ".txt" (note: include the dot in this case).
      • FlatFileResolver

        public FlatFileResolver​(Path rootDirectory)
        Initializes the resolver with the given root directory and an empty suffix. Files are cached permanently after first access.
        Parameters:
        rootDirectory - the root directory to resolve files relative to.
      • FlatFileResolver

        public FlatFileResolver​(Path rootDirectory,
                                String suffix,
                                DirectoryWatcher directoryWatcher)
        Initializes the resolver with the given root directory.
        Parameters:
        rootDirectory - the root directory to resolve files relative to.
        suffix - a suffix to append to property names such as a file extension, for instance ".txt" (note: include the dot in this case).
        directoryWatcher - if non-null then the resolver will use this watcher to update the cache when files change in the root directory.
    • Method Detail

      • getProperty

        public Optional<String> getProperty​(String key,
                                            boolean sensitive)
        Description copied from interface: PropertyResolver
        Returns the value of the specified property. The method returns an empty Optional if the property is not found. The resolved property has to be considered sensitive if sensitive is true and implementations are required to handle it with special attention (no logs, ...).
        Specified by:
        getProperty in interface PropertyResolver
        Parameters:
        key - The name of the requested property. The key can't be null.
        sensitive - true is the property value has to be considered a sensitive value (such as a password).
        Returns:
        An Optional string that contains the value of the requested property, or empty Optional if property is undefined.