Interface PropertyReader
public interface PropertyReader
Allows to read values from an abstracted source of properties.
-
Field Summary
Fields Modifier and Type Field Description static PropertyReaderEMPTYAPropertyReaderthat doesn't contain any property. -
Method Summary
Modifier and Type Method Description static PropertyReaderfromProperties(Properties props)Creates a newPropertyReaderreading properties from the givenPropertiesobject.static reactor.core.publisher.Mono<PropertyReader>fromPropertiesFile(Path path)Reads the properties from a Java properties file located at the givenPath.Stringread(String key)Reads a value associated with the given key.<T> TreadAs(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.Stream<String>readAsStream(String key, String separator)Reads the value as a stream of values, each element being separated with a separator character.Optional<String>readOptional(String key)Reads a value associated with the given key, if present.
-
Field Details
-
EMPTY
APropertyReaderthat doesn't contain any property.
-
-
Method Details
-
read
Reads a value associated with the given key. If no value is present,NoSuchElementExceptionis thrown.- Parameters:
key- the configuration key- Returns:
- the value associated with the key,
- Throws:
NoSuchElementException- if no value is present
-
readAs
Reads the value associated with the given key and maps it to an object via the given function. If no value is present,NoSuchElementExceptionis thrown.- Type Parameters:
T- the type of object to map the value to- Parameters:
key- the configuration keymapper- the function that maps the read value into an object- Returns:
- the object produced from the read value
-
readOptional
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
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 keyseparator- 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 theString.split(String)method internally. So characters like $ or | should be properly escaped- Returns:
- a Stream containing all elements
-
fromProperties
Creates a newPropertyReaderreading properties from the givenPropertiesobject.- Parameters:
props- thePropertiesobject to read- Returns:
- a new
PropertyReader
-
fromPropertiesFile
Reads the properties from a Java properties file located at the givenPath.- Parameters:
path- the path where the properties file is located- Returns:
- a Mono emitting a PropertyReader backed by the properties read from file
-