Package org.jfree.util
Class SortedConfigurationWriter
- java.lang.Object
-
- org.jfree.util.SortedConfigurationWriter
-
public class SortedConfigurationWriter extends java.lang.Object
Writes aConfiguration
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.
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description SortedConfigurationWriter()
The default constructor, does nothing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
ESCAPE_KEY
private static final int ESCAPE_KEY
A constant defining that text should be escaped in a way which is suitable for property keys.- See Also:
- Constant Field Values
-
ESCAPE_VALUE
private static final int ESCAPE_VALUE
A constant defining that text should be escaped in a way which is suitable for property values.- See Also:
- Constant Field Values
-
ESCAPE_COMMENT
private static final int ESCAPE_COMMENT
A constant defining that text should be escaped in a way which is suitable for property comments.- See Also:
- Constant Field Values
-
END_OF_LINE
private static final java.lang.String END_OF_LINE
The system-dependent End-Of-Line separator.
-
HEX_CHARS
private static final char[] HEX_CHARS
A lookup-table.
-
-
Method Detail
-
getDescription
protected java.lang.String getDescription(java.lang.String key)
Returns a description for the given key. This implementation returns null to indicate that no description should be written. Subclasses can overwrite this method to provide comments for every key. These descriptions will be included as inline comments.- Parameters:
key
- the key for which a description should be printed.- Returns:
- the description or null if no description should be printed.
-
save
public void save(java.lang.String filename, Configuration config) throws java.io.IOException
Saves the given configuration into a file specified by the given filename.- Parameters:
filename
- the filenameconfig
- the configuration- Throws:
java.io.IOException
- if an IOError occurs.
-
save
public void save(java.io.File file, Configuration config) throws java.io.IOException
Saves the given configuration into a file specified by the given file object.- Parameters:
file
- the target fileconfig
- the configuration- Throws:
java.io.IOException
- if an IOError occurs.
-
save
public void save(java.io.OutputStream outStream, Configuration config) throws java.io.IOException
Writes the configuration into the given output stream.- Parameters:
outStream
- the target output streamconfig
- the configuration- Throws:
java.io.IOException
- if writing fails.
-
writeDescription
private void writeDescription(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Writes a descriptive comment into the given print writer.- Parameters:
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.- Throws:
java.io.IOException
- if writing fails
-
saveConvert
private void saveConvert(java.lang.String text, int escapeMode, java.io.Writer writer) throws java.io.IOException
Performs the necessary conversion of an java string into a property escaped string.- Parameters:
text
- the text to be escapedescapeMode
- the mode that should be applied.writer
- the writer that should receive the content.- Throws:
java.io.IOException
- if writing fails
-
-