public final class PropertiesFile extends Object
Represents a properties file together with the ability to parse it from a CharSource.
This is similar to Properties but with a simpler format and without extending Map.
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.
| Modifier and Type | Method and 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.
|
public static PropertiesFile of(CharSource source)
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.
source - the properties file resourceUncheckedIOException - if an IO exception occursIllegalArgumentException - if the file cannot be parsedpublic static PropertiesFile of(PropertySet keyValueMap)
keyValueMap - the key-value property setpublic PropertySet getProperties()
The map of key-value properties is exposed by this method.
public boolean equals(Object obj)
The comparison checks the content.
public int hashCode()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.