package com.kodcu.service.config;

import com.esotericsoftware.yamlbeans.YamlWriter;
import com.kodcu.bean.Config;
import com.kodcu.bean.RecentFiles;
import com.kodcu.controller.ApplicationController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;

/**
 * Created by usta on 26.12.2014.
 */
@Component
public class YamlService {

    private final ApplicationController controller;
    
    @Autowired
    public YamlService(final ApplicationController controller) {
        this.controller = controller;
    }

    public void persist() throws IOException {
        Path configPath = controller.getConfigPath();
        File recentFileYml = configPath.resolve("recentFiles.yml").toFile();
        YamlWriter yamlWriter = new YamlWriter(new FileWriter(recentFileYml));
        yamlWriter.getConfig().setClassTag("RecentFiles", RecentFiles.class);
        yamlWriter.write(new RecentFiles(controller.getRecentFiles()));
        yamlWriter.close();

        //

        File configYml = configPath.resolve("config.yml").toFile();
        yamlWriter = new YamlWriter(new FileWriter(configYml));
        yamlWriter.getConfig().setClassTag("Config", Config.class);
        yamlWriter.write(controller.getConfig());
        yamlWriter.close();
    }
}

@@ -32,58 +32,8 @@
 g;%0A%0A
-import com.esotericsoftware.yamlbeans.YamlWriter;%0A
 impo
@@ -255,16 +255,48 @@
 mponent;
+%0Aimport org.yaml.snakeyaml.Yaml;
 %0A%0Aimport
@@ -826,32 +826,33 @@
 yml%22).toFile();%0A
+%0A
         YamlWrit
@@ -851,43 +851,58 @@
 Yaml
-Writer yamlWriter = new YamlWriter(
+ yaml=new Yaml();%0A        try(FileWriter writer = 
 new 
@@ -922,26 +922,27 @@
 centFileYml)
-)
 ;
+)%7B
 %0A        yam
@@ -942,102 +942,21 @@
     
-yamlWriter.getConfig().setClassTag(%22RecentFiles%22, RecentFiles.class);%0A        yamlWriter.write
+    yaml.dump
 (new
@@ -1000,329 +1000,28 @@
 s())
-)
-;%0A        yamlWriter.close();%0A%0A        //%0A%0A        File configYml = configPath.resolve(%22config.yml%22).toFile();%0A        yamlWriter = new YamlWriter(new FileWriter(configYml));%0A        yamlWriter.getConfig().setClassTag(%22Config%22, Config.class);%0A        yamlWriter.write(controller.getConfig());%0A        yamlWriter.close();
+, writer);%0A        %7D
 %0A   

Remove yamlbeans