Interface PropertyReader


  • public interface PropertyReader
    Allows to read values from an abstracted source of properties.
    • Method Detail

      • readAs

        <T> T readAs​(String key,
                     Function<? super String,​? extends T> mapper)
        Reads the value associated with the given key and maps it to an object via the given function. If no value is present, NoSuchElementException is thrown.
        Type Parameters:
        T - the type of object to map the value to
        Parameters:
        key - the configuration key
        mapper - the function that maps the read value into an object
        Returns:
        the object produced from the read value
      • readOptional

        Optional<String> readOptional​(String key)
        Reads a value associated with the given key, if present.
        Parameters:
        key - the configuration key
        Returns:
        the value associated with the key, if present
      • readAsStream

        Stream<String> readAsStream​(String key,
                                    String separator)
        Reads the value as a stream of values, each element being separated with a separator character. Let's say the value of the configuration entry "foo" is formatted as:
         bar:test:demon:hamburger
         
        Calling this method this way:
         readAsStream("foo", ":", String::toString);
         
        would return a Stream with the following elements:
         ["bar", "test", "demon", "hamburger"]
         
        Parameters:
        key - the configuration key
        separator - the character (or sequence of characters) that separates the elements in the raw string. Note that this is actually a regex as this parameter is directly passed to the String.split(String) method internally. So characters like $ or | should be properly escaped
        Returns:
        a Stream containing all elements
      • fromPropertiesFile

        static reactor.core.publisher.Mono<PropertyReader> fromPropertiesFile​(Path path)
        Reads the properties from a Java properties file located at the given Path.
        Parameters:
        path - the path where the properties file is located
        Returns:
        a Mono emitting a PropertyReader backed by the properties read from file