Search in sources :

Example 1 with YamlWriter

use of com.esotericsoftware.yamlbeans.YamlWriter in project audit4j-core by audit4j.

the class YAMLConfigProvider method generateConfig.

/**
 * {@inheritDoc}
 */
@Override
public void generateConfig(T config, String filePath) throws ConfigurationException {
    YamlWriter writer;
    try {
        writer = new YamlWriter(new FileWriter(filePath));
        writer.getConfig().setClassTag(clazz.getSimpleName(), clazz);
        writer.write(Configuration.DEFAULT);
        writer.close();
    } catch (IOException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_002");
    }
}
Also used : ConfigurationException(org.audit4j.core.exception.ConfigurationException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter)

Example 2 with YamlWriter

use of com.esotericsoftware.yamlbeans.YamlWriter in project audit4j-core by audit4j.

the class URLConfigurationIntTest method before.

@Before
public void before() {
    configFileLocation = System.getProperty("user.home") + "/audit4j.conf.yml";
    System.out.println(configFileLocation);
    YamlWriter writer;
    try {
        writer = new YamlWriter(new FileWriter(configFileLocation));
        writer.getConfig().setClassTag("Configuration", Configuration.class);
        writer.write(Configuration.DEFAULT);
        writer.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Before(org.junit.Before)

Example 3 with YamlWriter

use of com.esotericsoftware.yamlbeans.YamlWriter in project ASCIIGenome by dariober.

the class ASCIIGenomeHistory method write.

public void write(File outYaml) throws IOException {
    Map<String, Object> asciigenome_history = new HashMap<String, Object>();
    // List of commands
    List<String> lastCommands = new ArrayList<String>();
    int max_cmds = MAX_CMDS;
    for (String cmd : this.getCommands()) {
        if (max_cmds == 0) {
            break;
        }
        max_cmds--;
        lastCommands.add(cmd.trim());
    }
    asciigenome_history.put("commands", lastCommands);
    // List of files
    List<String> lastFiles = this.getFiles();
    lastFiles = lastFiles.subList(Math.max(0, lastFiles.size() - MAX_FILES), lastFiles.size());
    // Convert ArrayList#subList to List so the yaml file does show an odd data type.
    asciigenome_history.put("files", new ArrayList<String>(lastFiles));
    // Positions
    List<String> lastPos = this.getPositions();
    asciigenome_history.put("positions", lastPos);
    // Reference
    List<String> ref = this.getReference();
    if (ref != null && ref.size() > 0 && ref.get(0) != null && !ref.get(0).trim().isEmpty()) {
        asciigenome_history.put("reference", new ArrayList<String>(ref));
    }
    // Write yaml
    YamlWriter writer = new YamlWriter(new FileWriter(outYaml));
    writer.write(asciigenome_history);
    writer.close();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter)

Aggregations

YamlWriter (com.esotericsoftware.yamlbeans.YamlWriter)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConfigurationException (org.audit4j.core.exception.ConfigurationException)1 Before (org.junit.Before)1