org.apache.commons.configuration

Class PropertiesConfiguration.PropertiesWriter

public static class PropertiesConfiguration.PropertiesWriter extends FilterWriter

This class is used to write properties lines.
Field Summary
chardelimiter
The delimiter for multi-valued properties.
Constructor Summary
PropertiesWriter(Writer writer, char delimiter)
Constructor.
Method Summary
StringescapeKey(String key)
Escape the separators in the key.
StringescapeValue(Object value)
Escapes the given property value.
StringmakeSingleLineValue(List values)
Transforms a list of values into a single line value.
voidwriteComment(String comment)
Write a comment.
voidwriteln(String s)
Helper method for writing a line with the platform specific line ending.
voidwriteProperty(String key, Object value)
Write a property.
voidwriteProperty(String key, List values)
Write a property.
voidwriteProperty(String key, Object value, boolean forceSingleLine)
Writes the given property and its value.

Field Detail

delimiter

private char delimiter
The delimiter for multi-valued properties.

Constructor Detail

PropertiesWriter

public PropertiesWriter(Writer writer, char delimiter)
Constructor.

Parameters: writer a Writer object providing the underlying stream delimiter the delimiter character for multi-valued properties

Method Detail

escapeKey

private String escapeKey(String key)
Escape the separators in the key.

Parameters: key the key

Returns: the escaped key

Since: 1.2

escapeValue

private String escapeValue(Object value)
Escapes the given property value. Delimiter characters in the value will be escaped.

Parameters: value the property value

Returns: the escaped property value

Since: 1.3

makeSingleLineValue

private String makeSingleLineValue(List values)
Transforms a list of values into a single line value.

Parameters: values the list with the values

Returns: a string with the single line value (can be null)

Since: 1.3

writeComment

public void writeComment(String comment)
Write a comment.

Parameters: comment the comment to write

Throws: IOException if an I/O error occurs

writeln

public void writeln(String s)
Helper method for writing a line with the platform specific line ending.

Parameters: s the content of the line (may be null)

Throws: IOException if an error occurs

Since: 1.3

writeProperty

public void writeProperty(String key, Object value)
Write a property.

Parameters: key the key of the property value the value of the property

Throws: IOException if an I/O error occurs

writeProperty

public void writeProperty(String key, List values)
Write a property.

Parameters: key The key of the property values The array of values of the property

Throws: IOException if an I/O error occurs

writeProperty

public void writeProperty(String key, Object value, boolean forceSingleLine)
Writes the given property and its value. If the value happens to be a list, the forceSingleLine flag is evaluated. If it is set, all values are written on a single line using the list delimiter as separator.

Parameters: key the property key value the property value forceSingleLine the "force single line" flag

Throws: IOException if an error occurs

Since: 1.3