Class SortedConfigurationWriter

java.lang.Object
org.jfree.util.SortedConfigurationWriter

public class SortedConfigurationWriter extends Object
Writes a 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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    The system-dependent End-Of-Line separator.
    private static final int
    A constant defining that text should be escaped in a way which is suitable for property comments.
    private static final int
    A constant defining that text should be escaped in a way which is suitable for property keys.
    private static final int
    A constant defining that text should be escaped in a way which is suitable for property values.
    private static final char[]
    A lookup-table.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor, does nothing.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Returns a description for the given key.
    void
    save(File file, Configuration config)
    Saves the given configuration into a file specified by the given file object.
    void
    save(OutputStream outStream, Configuration config)
    Writes the configuration into the given output stream.
    void
    save(String filename, Configuration config)
    Saves the given configuration into a file specified by the given filename.
    private void
    saveConvert(String text, int escapeMode, Writer writer)
    Performs the necessary conversion of an java string into a property escaped string.
    private void
    Writes a descriptive comment into the given print writer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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:
    • 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:
    • 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:
    • END_OF_LINE

      private static final String END_OF_LINE
      The system-dependent End-Of-Line separator.
    • HEX_CHARS

      private static final char[] HEX_CHARS
      A lookup-table.
  • Constructor Details

    • SortedConfigurationWriter

      public SortedConfigurationWriter()
      The default constructor, does nothing.
  • Method Details

    • getDescription

      protected String getDescription(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(String filename, Configuration config) throws IOException
      Saves the given configuration into a file specified by the given filename.
      Parameters:
      filename - the filename
      config - the configuration
      Throws:
      IOException - if an IOError occurs.
    • save

      public void save(File file, Configuration config) throws IOException
      Saves the given configuration into a file specified by the given file object.
      Parameters:
      file - the target file
      config - the configuration
      Throws:
      IOException - if an IOError occurs.
    • save

      public void save(OutputStream outStream, Configuration config) throws IOException
      Writes the configuration into the given output stream.
      Parameters:
      outStream - the target output stream
      config - the configuration
      Throws:
      IOException - if writing fails.
    • writeDescription

      private void writeDescription(String text, Writer writer) throws 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:
      IOException - if writing fails
    • saveConvert

      private void saveConvert(String text, int escapeMode, Writer writer) throws IOException
      Performs the necessary conversion of an java string into a property escaped string.
      Parameters:
      text - the text to be escaped
      escapeMode - the mode that should be applied.
      writer - the writer that should receive the content.
      Throws:
      IOException - if writing fails