Search in sources :

Example 26 with Yaml

use of org.yaml.snakeyaml.Yaml in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImpl method initFromData.

private void initFromData(InputStream is) {
    Yaml yaml = new Yaml();
    @SuppressWarnings("unchecked") Map<String, Object> data = yaml.loadAs(is, Map.class);
    initFromData(data);
}
Also used : Yaml(org.yaml.snakeyaml.Yaml)

Example 27 with Yaml

use of org.yaml.snakeyaml.Yaml in project gitpitch by gitpitch.

the class YAMLOptions method build.

public static YAMLOptions build(PitchParams pp, GRSService grsService, DiskService diskService) {
    YAMLOptions yOpts = null;
    try {
        /*
             * Instantiate YAML parser.
             */
        Yaml yaml = new Yaml();
        /*
             * Build path to PITCHME_YAML on disk.
             */
        Path yPath = diskService.asPath(pp, PITCHME_YAML);
        File yFile = yPath.toFile();
        if (yFile.exists()) {
            /*
                 * Use YAML parser to transform YAML properties to Map.
                 */
            Map<String, String> yProps = (Map<String, String>) yaml.load(new FileReader(yPath.toFile()));
            /*
                 * Handle PITCHME.yaml empty file without properites.
                 */
            if (yProps == null) {
                yProps = new HashMap<String, String>();
            }
            log.debug("build: pp={}, props={}", pp, yProps);
            yOpts = new YAMLOptions(yProps, grsService);
        } else {
            log.debug("build: pp={}, yaml not found={}", yFile);
        }
    } catch (Exception yex) {
        log.warn("build: pp={}, parsing YAML ex={}", pp, yex);
    } finally {
        return yOpts;
    }
}
Also used : Path(java.nio.file.Path) FileReader(java.io.FileReader) File(java.io.File) Yaml(org.yaml.snakeyaml.Yaml)

Example 28 with Yaml

use of org.yaml.snakeyaml.Yaml in project wombat by PLOS.

the class RootConfiguration method yaml.

@Bean
public Yaml yaml() {
    final Yaml yaml;
    if (ignoreMissingProperty) {
        final Constructor contructor = new IgnoreMissingPropertyConstructor();
        yaml = new Yaml(contructor);
    } else {
        yaml = new Yaml();
    }
    return yaml;
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor) IgnoreMissingPropertyConstructor(org.ambraproject.wombat.config.yaml.IgnoreMissingPropertyConstructor) Yaml(org.yaml.snakeyaml.Yaml) IgnoreMissingPropertyConstructor(org.ambraproject.wombat.config.yaml.IgnoreMissingPropertyConstructor) Bean(org.springframework.context.annotation.Bean)

Example 29 with Yaml

use of org.yaml.snakeyaml.Yaml in project wombat by PLOS.

the class Theme method readYamlConfigValues.

private Map<?, ?> readYamlConfigValues(Theme theme, String configPath) throws IOException {
    // We don't actually validate whether a *.json file is valid JSON or just YAML.
    try (InputStream yamlStream = theme.fetchStaticResource(configPath + ".yaml");
        InputStream jsonStream = theme.fetchStaticResource(configPath + ".json")) {
        if (yamlStream == null && jsonStream == null) {
            return null;
        } else if (yamlStream != null && jsonStream != null) {
            String message = String.format("Redundant files at %s.yaml and %s.json in theme \"%s\"", configPath, configPath, theme.getKey());
            throw new IllegalStateException(message);
        }
        InputStream streamToUse = (yamlStream != null) ? yamlStream : jsonStream;
        // don't cache; it isn't threadsafe
        Yaml yaml = new Yaml();
        return yaml.loadAs(new InputStreamReader(streamToUse), Map.class);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Yaml(org.yaml.snakeyaml.Yaml)

Example 30 with Yaml

use of org.yaml.snakeyaml.Yaml in project weblogic-kubernetes-operator by oracle.

the class YamlUtils method newYaml.

public static Yaml newYaml() {
    // always make a new yaml object since it appears to be stateful
    // so there are problems if you try to use the same one to
    // parse different yamls at the same time
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setPrettyFlow(true);
    return new Yaml(new MyConstructor(), new MyRepresenter(), options);
}
Also used : DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

Yaml (org.yaml.snakeyaml.Yaml)253 Map (java.util.Map)92 HashMap (java.util.HashMap)73 IOException (java.io.IOException)55 FileInputStream (java.io.FileInputStream)47 InputStream (java.io.InputStream)47 File (java.io.File)43 DumperOptions (org.yaml.snakeyaml.DumperOptions)39 Constructor (org.yaml.snakeyaml.constructor.Constructor)27 ArrayList (java.util.ArrayList)25 FileNotFoundException (java.io.FileNotFoundException)21 List (java.util.List)21 Test (org.junit.Test)21 LinkedHashMap (java.util.LinkedHashMap)17 Writer (java.io.Writer)13 FileWriter (java.io.FileWriter)12 InputStreamReader (java.io.InputStreamReader)12 Path (java.nio.file.Path)12 FileReader (java.io.FileReader)10 Reader (java.io.Reader)9