public interface KeyValuesEnvironment
A facade over various system-level singletons used for loading key-value resources.
This interface provides a flexible mechanism for accessing and overriding system-level
components such as environment variables, system properties, and input streams.
Implementations can replace default system behaviors, enabling custom retrieval of environment variables or properties, or integrating custom logging mechanisms.
- API Note
- The API in this class uses traditional getter methods because the methods are often dynamic and to be consistent with the methods they are facading.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Key Values Resource focused logging facade and event capture.static interface
Interface for loading resources. -
Method Summary
Modifier and TypeMethodDescriptiondefault KeyValuesResource
If the loader builder is not passed any resources this resource will be used.default ClassLoader
Retrieves the class loader.default @Nullable Path
getCWD()
Gets the current working directory possibly using the passed in filesystem.default FileSystem
Retrieves theFileSystem
used for loading file resources.default KeyValuesEnvironment.Logger
Retrieves the logger instance used for logging messages.default @NonNull String[]
Retrieves the main method arguments.default Random
Retrieves a random number generator.Retrieves theKeyValuesEnvironment.ResourceLoader
used for loading resources as streams.default InputStream
Retrieves the standard input stream.Retrieves the current environment variables.default Properties
Retrieves the current system properties.
-
Method Details
-
defaultResource
If the loader builder is not passed any resources this resource will be used.- Returns:
- default resource is
classpath:/boot.properties
-
getMainArgs
Retrieves the main method arguments. By default, returns an empty array.- Returns:
- an array of main method arguments
-
getSystemProperties
Retrieves the current system properties. By default, delegates toSystem.getProperties()
.- Returns:
- the current system properties
-
getSystemEnv
Retrieves the current environment variables. By default, delegates toSystem.getenv()
.- Returns:
- a map of environment variables
-
getRandom
Retrieves a random number generator. By default, returns a newRandom
instance.- Returns:
- random.
-
getStandardInput
Retrieves the standard input stream. By default, delegates toSystem.in
.- Returns:
- the standard input stream or an empty input stream if
System.in
is null
-
getLogger
Retrieves the logger instance used for logging messages. By default, returns a noop logger.- Returns:
- the logger instance
-
getResourceLoader
Retrieves theKeyValuesEnvironment.ResourceLoader
used for loading resources as streams.- Returns:
- the resource stream loader instance
-
getFileSystem
Retrieves theFileSystem
used for loading file resources.- Returns:
- by default
FileSystems.getDefault()
.
-
getCWD
Gets the current working directory possibly using the passed in filesystem.- Returns:
- cwd or
null
-
getClassLoader
Retrieves the class loader. By default, delegates toClassLoader.getSystemClassLoader()
.- Returns:
- the system class loader
-