Search in sources :

Example 81 with Representer

use of org.yaml.snakeyaml.representer.Representer in project ozone by apache.

the class ContainerDataYaml method getYamlForContainerType.

/**
 * Given a ContainerType this method returns a Yaml representation of
 * the container properties.
 *
 * @param containerType type of container
 * @return Yamal representation of container properties
 *
 * @throws StorageContainerException if the type is unrecognized
 */
public static Yaml getYamlForContainerType(ContainerType containerType) throws StorageContainerException {
    PropertyUtils propertyUtils = new PropertyUtils();
    propertyUtils.setBeanAccess(BeanAccess.FIELD);
    propertyUtils.setAllowReadOnlyProperties(true);
    switch(containerType) {
        case KeyValueContainer:
            Representer representer = new ContainerDataRepresenter();
            representer.setPropertyUtils(propertyUtils);
            representer.addClassTag(KeyValueContainerData.class, KeyValueContainerData.KEYVALUE_YAML_TAG);
            Constructor keyValueDataConstructor = new ContainerDataConstructor();
            return new Yaml(keyValueDataConstructor, representer);
        default:
            throw new StorageContainerException("Unrecognized container Type " + "format " + containerType, ContainerProtos.Result.UNKNOWN_CONTAINER_TYPE);
    }
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) PropertyUtils(org.yaml.snakeyaml.introspector.PropertyUtils) Constructor(org.yaml.snakeyaml.constructor.Constructor) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) Yaml(org.yaml.snakeyaml.Yaml)

Example 82 with Representer

use of org.yaml.snakeyaml.representer.Representer in project Eidolons by IDemiurge.

the class YamlParser method main.

public static void main(String[] s) throws FileNotFoundException {
    Representer representer = new Representer();
    representer.addClassTag(YamlEntity.class, new Tag("!yah"));
    Yaml yaml = new Yaml(representer);
    Object load = yaml.load(new FileInputStream(new File("C:\\code\\Eidolons\\DungeonCraft\\src\\main\\resources\\data\\data.yaml")));
    load.getClass();
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Tag(org.yaml.snakeyaml.nodes.Tag) File(java.io.File) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream)

Aggregations

Representer (org.yaml.snakeyaml.representer.Representer)82 Yaml (org.yaml.snakeyaml.Yaml)77 DumperOptions (org.yaml.snakeyaml.DumperOptions)54 Constructor (org.yaml.snakeyaml.constructor.Constructor)25 LoaderOptions (org.yaml.snakeyaml.LoaderOptions)21 FileInputStream (java.io.FileInputStream)12 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)11 IOException (java.io.IOException)7 Tag (org.yaml.snakeyaml.nodes.Tag)7 File (java.io.File)6 TypeDescription (org.yaml.snakeyaml.TypeDescription)6 BaseConstructor (org.yaml.snakeyaml.constructor.BaseConstructor)5 FileNotFoundException (java.io.FileNotFoundException)4 InputStream (java.io.InputStream)4 PropertyUtils (org.yaml.snakeyaml.introspector.PropertyUtils)4 FileOutputStream (java.io.FileOutputStream)3 FileReader (java.io.FileReader)3 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Map (java.util.Map)3