Search in sources :

Example 6 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project eiger by wlloyd.

the class CliClient method loadHelp.

private CliUserHelp loadHelp() {
    final InputStream is = CliClient.class.getClassLoader().getResourceAsStream("org/apache/cassandra/cli/CliHelp.yaml");
    assert is != null;
    try {
        final Constructor constructor = new Constructor(CliUserHelp.class);
        TypeDescription desc = new TypeDescription(CliUserHelp.class);
        desc.putListPropertyType("commands", CliCommandHelp.class);
        final Yaml yaml = new Yaml(new Loader(constructor));
        return (CliUserHelp) yaml.load(is);
    } finally {
        FileUtils.closeQuietly(is);
    }
}
Also used : InputStream(java.io.InputStream) Constructor(org.yaml.snakeyaml.constructor.Constructor) TypeDescription(org.yaml.snakeyaml.TypeDescription) Loader(org.yaml.snakeyaml.Loader) Yaml(org.yaml.snakeyaml.Yaml)

Example 7 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project Essentials by drtshock.

the class YamlStorageReader method prepareConstructor.

private Constructor prepareConstructor(final Class<?> clazz) {
    final Constructor constructor = new BukkitConstructor(clazz, plugin);
    final Set<Class> classes = new HashSet<Class>();
    prepareConstructor(constructor, classes, clazz);
    return constructor;
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor)

Example 8 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project cassandra by apache.

the class YamlConfigurationLoader method loadConfig.

public Config loadConfig(URL url) throws ConfigurationException {
    try {
        logger.debug("Loading settings from {}", url);
        byte[] configBytes;
        try (InputStream is = url.openStream()) {
            configBytes = ByteStreams.toByteArray(is);
        } catch (IOException e) {
            // getStorageConfigURL should have ruled this out
            throw new AssertionError(e);
        }
        Constructor constructor = new CustomConstructor(Config.class);
        PropertiesChecker propertiesChecker = new PropertiesChecker();
        constructor.setPropertyUtils(propertiesChecker);
        Yaml yaml = new Yaml(constructor);
        Config result = loadConfig(yaml, configBytes);
        propertiesChecker.check();
        return result;
    } catch (YAMLException e) {
        throw new ConfigurationException("Invalid yaml: " + url + SystemUtils.LINE_SEPARATOR + " Error: " + e.getMessage(), false);
    }
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Constructor(org.yaml.snakeyaml.constructor.Constructor) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml)

Example 9 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project storm by apache.

the class FluxParser method yaml.

private static Yaml yaml() {
    Constructor constructor = new Constructor(TopologyDef.class);
    TypeDescription topologyDescription = new TypeDescription(TopologyDef.class);
    topologyDescription.putListPropertyType("spouts", SpoutDef.class);
    topologyDescription.putListPropertyType("bolts", BoltDef.class);
    topologyDescription.putListPropertyType("includes", IncludeDef.class);
    constructor.addTypeDescription(topologyDescription);
    Yaml yaml = new Yaml(constructor);
    return yaml;
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor) TypeDescription(org.yaml.snakeyaml.TypeDescription) Yaml(org.yaml.snakeyaml.Yaml)

Example 10 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project spring-boot by spring-projects.

the class YamlConfigurationFactory method afterPropertiesSet.

@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
    if (this.yaml == null) {
        Assert.state(this.resource != null, "Resource should not be null");
        this.yaml = StreamUtils.copyToString(this.resource.getInputStream(), Charset.defaultCharset());
    }
    Assert.state(this.yaml != null, "Yaml document should not be null: " + "either set it directly or set the resource to load it from");
    if (logger.isTraceEnabled()) {
        logger.trace(String.format("Yaml document is %n%s", this.yaml));
    }
    Constructor constructor = new YamlJavaBeanPropertyConstructor(this.type, this.propertyAliases);
    this.configuration = (T) (new Yaml(constructor)).load(this.yaml);
    if (this.validator != null) {
        validate();
    }
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

Constructor (org.yaml.snakeyaml.constructor.Constructor)10 Yaml (org.yaml.snakeyaml.Yaml)8 TypeDescription (org.yaml.snakeyaml.TypeDescription)4 InputStream (java.io.InputStream)3 YAMLException (org.yaml.snakeyaml.error.YAMLException)3 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOError (java.io.IOError)1 InputStreamReader (java.io.InputStreamReader)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 RequestValidationException (org.apache.cassandra.exceptions.RequestValidationException)1 Loader (org.yaml.snakeyaml.Loader)1 BaseConstructor (org.yaml.snakeyaml.constructor.BaseConstructor)1 CustomClassLoaderConstructor (org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor)1 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)1 PropertyUtils (org.yaml.snakeyaml.introspector.PropertyUtils)1