Class PropertiesFile
- java.lang.Object
-
- com.opengamma.strata.collect.io.PropertiesFile
-
public final class PropertiesFile extends Object
A properties file.Represents a properties file together with the ability to parse it from a
CharSource
. This is similar toProperties
but with a simpler format and without extendingMap
. Duplicate keys are allowed and handled.The properties file format used here is deliberately simple. There is only one element - key-value pairs.
The key is separated from the value using the '=' symbol. The string ' = ' is searched for before '=' to allow an equals sign to be present in the key, which implies that this string cannot be in either the key or the value. Duplicate keys are allowed. For example 'key = value'. The equals sign and value may be omitted, in which case the value is an empty string.
Keys and values are trimmed. Blank lines are ignored. Whole line comments begin with hash '#' or semicolon ';'. No escape format is available. Lookup is case sensitive.
This example explains the format:
# line comment key = value month = January
The aim of this class is to parse the basic format. Interpolation of variables is not supported.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Checks if this file equals another.PropertySet
getProperties()
Gets all the key-value properties of this file.int
hashCode()
Returns a suitable hash code for the file.static PropertiesFile
of(CharSource source)
Parses the specified source as a properties file.static PropertiesFile
of(PropertySet keyValueMap)
Obtains an instance from a key-value property set.String
toString()
Returns a string describing the file.
-
-
-
Method Detail
-
of
public static PropertiesFile of(CharSource source)
Parses the specified source as a properties file.This parses the specified character source expecting a properties file format. The resulting instance can be queried for each key and value.
Properties files sometimes contain a Unicode Byte Order Mark. Callers are responsible for handling this, such as by using
UnicodeBom
.- Parameters:
source
- the properties file resource- Returns:
- the properties file
- Throws:
UncheckedIOException
- if an IO exception occursIllegalArgumentException
- if the file cannot be parsed
-
of
public static PropertiesFile of(PropertySet keyValueMap)
Obtains an instance from a key-value property set.- Parameters:
keyValueMap
- the key-value property set- Returns:
- the properties file
-
getProperties
public PropertySet getProperties()
Gets all the key-value properties of this file.The map of key-value properties is exposed by this method.
- Returns:
- the key-value properties
-
equals
public boolean equals(Object obj)
Checks if this file equals another.The comparison checks the content.
-
hashCode
public int hashCode()
Returns a suitable hash code for the file.
-
-