Package org.apache.commons.configuration
Class PropertiesConfiguration.PropertiesWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.FilterWriter
-
- org.apache.commons.configuration.PropertiesConfiguration.PropertiesWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
- Enclosing class:
- PropertiesConfiguration
public static class PropertiesConfiguration.PropertiesWriter extends java.io.FilterWriter
This class is used to write properties lines. The most important method iswriteProperty(String, Object, boolean), which is called during a save operation for each property found in the configuration.
-
-
Constructor Summary
Constructors Constructor Description PropertiesWriter(java.io.Writer writer, char delimiter)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringfetchSeparator(java.lang.String key, java.lang.Object value)Returns the separator to be used for the given property.java.lang.StringgetCurrentSeparator()Returns the current property separator.java.lang.StringgetGlobalSeparator()Returns the global property separator.java.lang.StringgetLineSeparator()Returns the line separator.voidsetCurrentSeparator(java.lang.String currentSeparator)Sets the current property separator.voidsetGlobalSeparator(java.lang.String globalSeparator)Sets the global property separator.voidsetLineSeparator(java.lang.String lineSeparator)Sets the line separator.voidwriteComment(java.lang.String comment)Write a comment.voidwriteln(java.lang.String s)Helper method for writing a line with the platform specific line ending.voidwriteProperty(java.lang.String key, java.lang.Object value)Write a property.voidwriteProperty(java.lang.String key, java.lang.Object value, boolean forceSingleLine)Writes the given property and its value.voidwriteProperty(java.lang.String key, java.util.List<?> values)Write a property.
-
-
-
Constructor Detail
-
PropertiesWriter
public PropertiesWriter(java.io.Writer writer, char delimiter)
Constructor.- Parameters:
writer- a Writer object providing the underlying streamdelimiter- the delimiter character for multi-valued properties
-
-
Method Detail
-
getCurrentSeparator
public java.lang.String getCurrentSeparator()
Returns the current property separator.- Returns:
- the current property separator
- Since:
- 1.7
-
setCurrentSeparator
public void setCurrentSeparator(java.lang.String currentSeparator)
Sets the current property separator. This separator is used when writing the next property.- Parameters:
currentSeparator- the current property separator- Since:
- 1.7
-
getGlobalSeparator
public java.lang.String getGlobalSeparator()
Returns the global property separator.- Returns:
- the global property separator
- Since:
- 1.7
-
setGlobalSeparator
public void setGlobalSeparator(java.lang.String globalSeparator)
Sets the global property separator. This separator corresponds to theglobalSeparatorproperty ofPropertiesConfigurationLayout. It defines the separator to be used for all properties. If it is undefined, the current separator is used.- Parameters:
globalSeparator- the global property separator- Since:
- 1.7
-
getLineSeparator
public java.lang.String getLineSeparator()
Returns the line separator.- Returns:
- the line separator
- Since:
- 1.7
-
setLineSeparator
public void setLineSeparator(java.lang.String lineSeparator)
Sets the line separator. Each line written by this writer is terminated with this separator. If not set, the platform-specific line separator is used.- Parameters:
lineSeparator- the line separator to be used- Since:
- 1.7
-
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 propertyvalue- 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 propertyvalues- 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, theforceSingleLineflag is evaluated. If it is set, all values are written on a single line using the list delimiter as separator.- Parameters:
key- the property keyvalue- the property valueforceSingleLine- 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
-
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
-
fetchSeparator
protected java.lang.String fetchSeparator(java.lang.String key, java.lang.Object value)
Returns the separator to be used for the given property. This method is called bywriteProperty(). The string returned here is used as separator between the property key and its value. Per default the method checks whether a global separator is set. If this is the case, it is returned. Otherwise the separator returned bygetCurrentSeparator()is used, which was set by the associated layout object. Derived classes may implement a different strategy for defining the separator.- Parameters:
key- the property keyvalue- the value- Returns:
- the separator to be used
- Since:
- 1.7
-
-