public static class PropertiesConfiguration.PropertiesWriter extends FilterWriter
writeProperty(String, Object, boolean)
, which is called during a save operation for each property found in
the configuration.out
Constructor and Description |
---|
PropertiesWriter(Writer writer,
ListDelimiterHandler delHandler)
Creates a new instance of
PropertiesWriter . |
PropertiesWriter(Writer writer,
ListDelimiterHandler delHandler,
ValueTransformer valueTransformer)
Creates a new instance of
PropertiesWriter . |
Modifier and Type | Method and Description |
---|---|
protected String |
escapeKey(String key)
Escapes the key of a property before it gets written to file.
|
protected String |
fetchSeparator(String key,
Object value)
Returns the separator to be used for the given property.
|
String |
getCurrentSeparator()
Returns the current property separator.
|
ListDelimiterHandler |
getDelimiterHandler()
Returns the delimiter handler for properties with multiple values.
|
String |
getGlobalSeparator()
Returns the global property separator.
|
String |
getLineSeparator()
Returns the line separator.
|
void |
setCurrentSeparator(String currentSeparator)
Sets the current property separator.
|
void |
setGlobalSeparator(String globalSeparator)
Sets the global property separator.
|
void |
setLineSeparator(String lineSeparator)
Sets the line separator.
|
void |
writeComment(String comment)
Write a comment.
|
void |
writeln(String s)
Helper method for writing a line with the platform specific line ending.
|
void |
writeProperty(String key,
List<?> values)
Write a property.
|
void |
writeProperty(String key,
Object value)
Write a property.
|
void |
writeProperty(String key,
Object value,
boolean forceSingleLine)
Writes the given property and its value.
|
public PropertiesWriter(Writer writer, ListDelimiterHandler delHandler)
PropertiesWriter
.writer
- a Writer object providing the underlying streamdelHandler
- the delimiter handler for dealing with properties with multiple valuespublic PropertiesWriter(Writer writer, ListDelimiterHandler delHandler, ValueTransformer valueTransformer)
PropertiesWriter
.writer
- a Writer object providing the underlying streamdelHandler
- the delimiter handler for dealing with properties with multiple valuesvalueTransformer
- the value transformer used to escape property valuesprotected String escapeKey(String key)
key
- the keyprotected String fetchSeparator(String key, Object value)
writeProperty()
. 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 by
getCurrentSeparator()
is used, which was set by the associated layout object. Derived classes may implement a
different strategy for defining the separator.key
- the property keyvalue
- the valuepublic String getCurrentSeparator()
public ListDelimiterHandler getDelimiterHandler()
public String getGlobalSeparator()
public String getLineSeparator()
public void setCurrentSeparator(String currentSeparator)
currentSeparator
- the current property separatorpublic void setGlobalSeparator(String globalSeparator)
globalSeparator
property of
PropertiesConfigurationLayout
. It defines the separator to be used for all properties. If it is undefined,
the current separator is used.globalSeparator
- the global property separatorpublic void setLineSeparator(String lineSeparator)
lineSeparator
- the line separator to be usedpublic void writeComment(String comment) throws IOException
comment
- the comment to writeIOException
- if an I/O error occurs.public void writeln(String s) throws IOException
s
- the content of the line (may be null)IOException
- if an error occurspublic void writeProperty(String key, List<?> values) throws IOException
key
- The key of the propertyvalues
- The array of values of the propertyIOException
- if an I/O error occurs.public void writeProperty(String key, Object value) throws IOException
key
- the key of the propertyvalue
- the value of the propertyIOException
- if an I/O error occurs.public void writeProperty(String key, Object value, boolean forceSingleLine) throws IOException
forceSingleLine
flag is
evaluated. If it is set, all values are written on a single line using the list delimiter as separator.key
- the property keyvalue
- the property valueforceSingleLine
- the "force single line" flagIOException
- if an error occursCopyright © 2001–2022 The Apache Software Foundation. All rights reserved.