Search in sources :

Example 11 with DumperOptions

use of org.yaml.snakeyaml.DumperOptions in project watson by totemo.

the class ChatHighlighter method saveHighlights.

// loadHighlights
// --------------------------------------------------------------------------
/**
   * Save the highlights to the configuration file.
   */
public void saveHighlights() {
    try {
        File file = new File(Controller.getModDirectory(), CHAT_HIGHLIGHTS_FILE);
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        try {
            ArrayList<Object> highlights = new ArrayList<Object>();
            for (Highlight hl : _highlights) {
                highlights.add(hl.getSaveData());
            }
            HashMap<String, Object> root = new HashMap<String, Object>();
            root.put("highlights", highlights);
            DumperOptions options = new DumperOptions();
            options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
            Yaml yaml = new Yaml(options);
            yaml.dump(root, writer);
        } finally {
            writer.close();
        }
    } catch (Exception ex) {
        Log.exception(Level.SEVERE, "error saving chat highlights: ", ex);
    }
}
Also used : HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) File(java.io.File)

Aggregations

DumperOptions (org.yaml.snakeyaml.DumperOptions)11 Yaml (org.yaml.snakeyaml.Yaml)9 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DefaultMustacheFactory (com.github.mustachejava.DefaultMustacheFactory)2 Mustache (com.github.mustachejava.Mustache)2 MustacheFactory (com.github.mustachejava.MustacheFactory)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 AutoValue (com.google.auto.value.AutoValue)1 Multimaps (com.google.common.collect.Multimaps)1 SortedSetMultimap (com.google.common.collect.SortedSetMultimap)1 TreeMultimap (com.google.common.collect.TreeMultimap)1 SeverityLevel (com.google.errorprone.BugPattern.SeverityLevel)1 Target (com.google.errorprone.DocGenTool.Target)1