Interface PropertyReader


public interface PropertyReader
Allows to read values from an abstracted source of properties.
  • Field Details

  • Method Details

    • read

      String read​(String key)
      Reads a value associated with the given key. If no value is present, NoSuchElementException is thrown.
      Parameters:
      key - the configuration key
      Returns:
      the value associated with the key,
      Throws:
      NoSuchElementException - if no value is present
    • 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
    • fromProperties

      static PropertyReader fromProperties​(Properties props)
      Creates a new PropertyReader reading properties from the given Properties object.
      Parameters:
      props - the Properties object to read
      Returns:
      a new PropertyReader
    • 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