Package com.trafficparrot.sdk
Class PropertiesHelper
java.lang.Object
com.trafficparrot.sdk.PropertiesHelper
Reads
.properties files and comma-separated property values, for an extension that keeps its own settings
in a file.
Properties settings = PropertiesHelper.readPropertiesFile(Paths.get("my-extension.properties"));
List<String> hosts = PropertiesHelper.parseList(settings.getProperty("hosts"));
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSplits a comma-separated property value into its items.static PropertiesreadPropertiesFile(String propertiesResource) Reads a.propertiesresource from the classpath, through the class loader that loaded the SDK.static PropertiesreadPropertiesFile(Path propertiesFile) Reads a.propertiesfile from disk.
-
Constructor Details
-
PropertiesHelper
public PropertiesHelper()Not needed, since every method is static. Declared so that code which creates an instance keeps working.
-
-
Method Details
-
parseList
Splits a comma-separated property value into its items.Each item is returned as written, so
"a, b"gives"a"and" b": trim the items if the value may carry spaces. An empty item at the start or in the middle is kept (",a,,b"gives four items); empty items at the end are dropped.- Parameters:
propertyValue- the value to split; may be null- Returns:
- the items in order, or an empty list when the value is null, empty or only whitespace
-
readPropertiesFile
Reads a.propertiesresource from the classpath, through the class loader that loaded the SDK.- Parameters:
propertiesResource- the resource's name on the classpath, such as"my-extension.properties"- Returns:
- the properties the resource holds
- Throws:
IllegalArgumentException- if the resource cannot be readNullPointerException- if the classpath has no resource with this name
-
readPropertiesFile
Reads a.propertiesfile from disk.- Parameters:
propertiesFile- the file to read- Returns:
- the properties the file holds
- Throws:
IllegalArgumentException- if the file does not exist, is a directory or cannot be read
-