Class 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 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.

    • 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.

        source - the properties file resource
        the properties file
        UncheckedIOException - if an IO exception occurs
        IllegalArgumentException - if the file cannot be parsed
      • of

        public static PropertiesFile of​(PropertySet keyValueMap)
        Obtains an instance from a key-value property set.
        keyValueMap - the key-value property set
        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.

        the key-value properties
      • equals

        public boolean equals​(Object obj)
        Checks if this file equals another.

        The comparison checks the content.

        equals in class Object
        obj - the other section, null returns false
        true if equal
      • hashCode

        public int hashCode()
        Returns a suitable hash code for the file.
        hashCode in class Object
        the hash code
      • toString

        public String toString()
        Returns a string describing the file.
        toString in class Object
        the descriptive string