org.apache.commons.configuration
Class PropertiesConfiguration.PropertiesWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.FilterWriter
          extended by org.apache.commons.configuration.PropertiesConfiguration.PropertiesWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable
Enclosing class:
PropertiesConfiguration

public static class PropertiesConfiguration.PropertiesWriter
extends java.io.FilterWriter

This class is used to write properties lines.


Field Summary
private  char delimiter
          The delimiter for multi-valued properties.
 
Fields inherited from class java.io.FilterWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
PropertiesConfiguration.PropertiesWriter(java.io.Writer writer, char delimiter)
          Constructor.
 
Method Summary
private  java.lang.String escapeKey(java.lang.String key)
          Escape the separators in the key.
private  java.lang.String escapeValue(java.lang.Object value)
          Escapes the given property value.
private  java.lang.String makeSingleLineValue(java.util.List values)
          Transforms a list of values into a single line value.
 void writeComment(java.lang.String comment)
          Write a comment.
 void writeln(java.lang.String s)
          Helper method for writing a line with the platform specific line ending.
 void writeProperty(java.lang.String key, java.util.List values)
          Write a property.
 void writeProperty(java.lang.String key, java.lang.Object value)
          Write a property.
 void writeProperty(java.lang.String key, java.lang.Object value, boolean forceSingleLine)
          Writes the given property and its value.
 
Methods inherited from class java.io.FilterWriter
close, flush, write, write, write
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delimiter

private char delimiter
The delimiter for multi-valued properties.

Constructor Detail

PropertiesConfiguration.PropertiesWriter

public PropertiesConfiguration.PropertiesWriter(java.io.Writer writer,
                                                char delimiter)
Constructor.

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

writeProperty

public void writeProperty(java.lang.String key,
                          java.lang.Object value)
                   throws java.io.IOException
Write a property.

Parameters:
key - the key of the property
value - the value of the property
Throws:
java.io.IOException - if an I/O error occurs

writeProperty

public void writeProperty(java.lang.String key,
                          java.util.List values)
                   throws java.io.IOException
Write a property.

Parameters:
key - The key of the property
values - The array of values of the property
Throws:
java.io.IOException - if an I/O error occurs

writeProperty

public void writeProperty(java.lang.String key,
                          java.lang.Object value,
                          boolean forceSingleLine)
                   throws java.io.IOException
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:
java.io.IOException - if an error occurs
Since:
1.3

writeComment

public void writeComment(java.lang.String comment)
                  throws java.io.IOException
Write a comment.

Parameters:
comment - the comment to write
Throws:
java.io.IOException - if an I/O error occurs

escapeKey

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

Parameters:
key - the key
Returns:
the escaped key
Since:
1.2

escapeValue

private java.lang.String escapeValue(java.lang.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 java.lang.String makeSingleLineValue(java.util.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

writeln

public void writeln(java.lang.String s)
             throws java.io.IOException
Helper method for writing a line with the platform specific line ending.

Parameters:
s - the content of the line (may be null)
Throws:
java.io.IOException - if an error occurs
Since:
1.3