PropertiesParser class abstract final

Reads text in the .properties format (key=value lines) into a map.

It is the parser behind @PropertySource files and message bundles (messages.properties), as java.util.Properties is in Spring. Config files (application.properties) are read as Spring Boot reads them, by PropertiesPropertySourceLoader, which also knows #--- documents and key[]=a,b lists. Applications only write such files; call it directly to read a properties text of your own, such as a file uploaded by a user.

It reads the text exactly as java.util.Properties.load does: =, : or whitespace separate a key from its value, # and ! start a comment line (also after leading whitespace), a line ending in an odd number of backslashes continues on the next one (whose leading whitespace is dropped), and \t \n \r \f, \uXXXX and \ before any other character are escapes, in keys too. Whitespace is a space, a tab or a form feed only: other spaces (U+3000, a no-break space, a vertical tab) are text. As in Java, a line holding only a backslash joins nothing: the next line starts afresh (a comment stays one, a blank line ends it), and at the end of the text it is an empty key. Keys keep file order; a repeated key keeps its last value; trailing spaces of a value are kept. A byte order mark is text too, so it becomes part of the first key, as in Java.

final map = PropertiesParser.parse('''
# comment
app.name = Demo
app.greeting: Hello \\
    world
''');
map['app.greeting']; // 'Hello world'

Spring (Java):

// Spring delegates to java.util.Properties:
Properties props = new Properties();
props.load(new StringReader(content));

The content is a Dart string, already decoded (as UTF-8 unless the caller chose otherwise), not ISO-8859-1 bytes as in Properties.load(InputStream).

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

parse(String content) → Map<String, String>
Parses content into keys and values, in file order.