Class SortedConfigurationWriter


  • public class SortedConfigurationWriter
    extends java.lang.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 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.
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
    • Constructor Detail

      • SortedConfigurationWriter

        public SortedConfigurationWriter()
        The default constructor, does nothing.
    • 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 filename
        config - 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 file
        config - 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 stream
        config - 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 escaped
        escapeMode - the mode that should be applied.
        writer - the writer that should receive the content.
        Throws:
        java.io.IOException - if writing fails