Class PropertiesLoader
java.lang.Object
org.codice.ddf.platform.util.properties.PropertiesLoader
Utility class that attempts several different methods for loading in properties files from the
classpath or file system. The strategies are attempted in the following order:
- Spring (default class loader) uses utilities found in Spring-Core to load properties.
- Spring (given class loader) does the same as above, but with respect to the given class loader.
- Direct file system loading; useful when the properties have a fully-qualified absolute
path. Relative paths are also valid, and loading attempts path resolution using (in order):
- The relative path prepended with the
karaf.homeproperty - The relative path prepended with the
ddf.homeproperty - The relative path itself, without any modification
- The relative path prepended with the
- Resource loading using Java's built in resource system
If all strategies fail, then the returned Properties object will be empty.
-
Method Summary
Modifier and TypeMethodDescriptionstatic PropertiesLoaderloadProperties(String propertiesFile) Load properties from a file with no classloader specified.loadProperties(String propertiesFile, ClassLoader classLoader) Will attempt to load properties from a file using the given classloader.loadPropertiesWithoutSystemPropertySubstitution(String propertiesFile, ClassLoader classLoader) Will attempt to load properties from a file using the given classloader without replacing the system properties with their value.<K,V> Map <K, V> toMap(Properties properties) Converts an instance of Properties to an instance of a Map, which is the preferred API for working with key-value collections.
-
Method Details
-
getInstance
-
toMap
Converts an instance of Properties to an instance of a Map, which is the preferred API for working with key-value collections.- Type Parameters:
K- the object type of the key in the returned mapV- the object type of the value in the returned map- Parameters:
properties- the properties object whose elements should be in the resultant map- Returns:
- a new map with all elements of the given properties, or empty if the properties were null
-
loadProperties
Load properties from a file with no classloader specified.- Parameters:
propertiesFile- the resource name or the file path of the properties file- Returns:
- Properties deserialized from the specified file, or empty if the load failed
-
loadProperties
Will attempt to load properties from a file using the given classloader. If that fails, several other methods will be tried until the properties file is located.- Parameters:
propertiesFile- the resource name or the file path of the properties fileclassLoader- the class loader with access to the properties file- Returns:
- Properties deserialized from the specified file, or empty if the load failed
-
loadPropertiesWithoutSystemPropertySubstitution
public Properties loadPropertiesWithoutSystemPropertySubstitution(String propertiesFile, ClassLoader classLoader) Will attempt to load properties from a file using the given classloader without replacing the system properties with their value. If that fails, several other methods will be tried until the properties file is located.- Parameters:
propertiesFile- the resource name or the file path of the properties fileclassLoader- the class loader with access to the properties file- Returns:
- Properties deserialized from the specified file, or empty if the load failed
-