in src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java [479:521]
public void save(final PropertiesConfiguration config, final Writer writer) throws ConfigurationException {
try {
@SuppressWarnings("resource") // createPropertiesReader wraps the writer.
final PropertiesConfiguration.PropertiesWriter pWriter = config.getIOFactory().createPropertiesWriter(writer, config.getListDelimiterHandler());
pWriter.setGlobalSeparator(getGlobalSeparator());
if (getLineSeparator() != null) {
pWriter.setLineSeparator(getLineSeparator());
}
if (headerComment != null) {
writeComment(pWriter, getCanonicalHeaderComment(true));
}
boolean firstKey = true;
for (final String key : getKeys()) {
if (config.containsKeyInternal(key)) {
// preset header comment needs to be separated from key
if (firstKey && headerComment != null && getBlankLinesBefore(key) == 0) {
pWriter.writeln(null);
}
// Output blank lines before property
for (int i = 0; i < getBlankLinesBefore(key); i++) {
pWriter.writeln(null);
}
// Output the comment
writeComment(pWriter, getCanonicalComment(key, true));
// Output the property and its value
final boolean singleLine = isForceSingleLine() || isSingleLine(key);
pWriter.setCurrentSeparator(getSeparator(key));
pWriter.writeProperty(key, config.getPropertyInternal(key), singleLine);
}
firstKey = false;
}
writeComment(pWriter, getCanonicalFooterCooment(true));
pWriter.flush();
} catch (final IOException ioex) {
throw new ConfigurationException(ioex);
}
}