Search in sources :

Example 1 with ConfigurationException

use of org.audit4j.core.exception.ConfigurationException 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 ConfigurationException

use of org.audit4j.core.exception.ConfigurationException in project audit4j-core by audit4j.

the class YAMLConfigProvider method readConfig.

/**
 * {@inheritDoc}
 *
 * @see org.audit4j.core.ConfigProvider#readConfig(java.io.InputStream)
 */
@SuppressWarnings("unchecked")
@Override
public T readConfig(InputStream fileAsStream) throws ConfigurationException {
    InputStreamReader streamReader = new InputStreamReader(fileAsStream);
    try {
        YamlReader reader = new YamlReader(streamReader);
        reader.getConfig().setClassTag(clazz.getSimpleName(), clazz);
        return (T) reader.read();
    } catch (YamlException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_002", e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) InputStreamReader(java.io.InputStreamReader) ConfigurationException(org.audit4j.core.exception.ConfigurationException) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 3 with ConfigurationException

use of org.audit4j.core.exception.ConfigurationException in project audit4j-core by audit4j.

the class YAMLConfigProvider method readConfig.

/**
 * {@inheritDoc}
 *
 * @see org.audit4j.core.ConfigProvider#readConfig(java.lang.String)
 */
@SuppressWarnings("unchecked")
@Override
public T readConfig(String filePath) throws ConfigurationException {
    try {
        YamlReader reader = new YamlReader(new FileReader(filePath));
        reader.getConfig().setClassTag(clazz.getSimpleName(), clazz);
        return (T) reader.read();
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_001", e);
    } catch (YamlException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_002", e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) ConfigurationException(org.audit4j.core.exception.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Aggregations

ConfigurationException (org.audit4j.core.exception.ConfigurationException)3 YamlException (com.esotericsoftware.yamlbeans.YamlException)2 YamlReader (com.esotericsoftware.yamlbeans.YamlReader)2 YamlWriter (com.esotericsoftware.yamlbeans.YamlWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1