public class SortedConfigurationWriter
extends java.lang.Object
Configuration
instance into a property file, where
the keys are sorted by their name. Writing sorted keys make it easier for
users to find and change properties in the file.Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
END_OF_LINE
The system-dependent End-Of-Line separator.
|
private static int |
ESCAPE_COMMENT
A constant defining that text should be escaped in a way
which is suitable for property comments.
|
private static int |
ESCAPE_KEY
A constant defining that text should be escaped in a way
which is suitable for property keys.
|
private static int |
ESCAPE_VALUE
A constant defining that text should be escaped in a way
which is suitable for property values.
|
private static char[] |
HEX_CHARS
A lookup-table.
|
Constructor and Description |
---|
SortedConfigurationWriter()
The default constructor, does nothing.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
getDescription(java.lang.String key)
Returns a description for the given key.
|
void |
save(java.io.File file,
Configuration config)
Saves the given configuration into a file specified by the given
file object.
|
void |
save(java.io.OutputStream outStream,
Configuration config)
Writes the configuration into the given output stream.
|
void |
save(java.lang.String filename,
Configuration config)
Saves the given configuration into a file specified by the given
filename.
|
private void |
saveConvert(java.lang.String text,
int escapeMode,
java.io.Writer writer)
Performs the necessary conversion of an java string into a property
escaped string.
|
private void |
writeDescription(java.lang.String text,
java.io.Writer writer)
Writes a descriptive comment into the given print writer.
|
private static final int ESCAPE_KEY
private static final int ESCAPE_VALUE
private static final int ESCAPE_COMMENT
private static final java.lang.String END_OF_LINE
private static final char[] HEX_CHARS
public SortedConfigurationWriter()
protected java.lang.String getDescription(java.lang.String key)
key
- the key for which a description should be printed.public void save(java.lang.String filename, Configuration config) throws java.io.IOException
filename
- the filenameconfig
- the configurationjava.io.IOException
- if an IOError occurs.public void save(java.io.File file, Configuration config) throws java.io.IOException
file
- the target fileconfig
- the configurationjava.io.IOException
- if an IOError occurs.public void save(java.io.OutputStream outStream, Configuration config) throws java.io.IOException
outStream
- the target output streamconfig
- the configurationjava.io.IOException
- if writing fails.private void writeDescription(java.lang.String text, java.io.Writer writer) throws java.io.IOException
text
- the text to be written. If it contains more than
one line, every line will be prepended by the comment character.writer
- the writer that should receive the content.java.io.IOException
- if writing failsprivate void saveConvert(java.lang.String text, int escapeMode, java.io.Writer writer) throws java.io.IOException
text
- the text to be escapedescapeMode
- the mode that should be applied.writer
- the writer that should receive the content.java.io.IOException
- if writing fails