当前位置: 首页>>代码示例>>Java>>正文


Java DumperOptions类代码示例

本文整理汇总了Java中org.yaml.snakeyaml.DumperOptions的典型用法代码示例。如果您正苦于以下问题:Java DumperOptions类的具体用法?Java DumperOptions怎么用?Java DumperOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DumperOptions类属于org.yaml.snakeyaml包,在下文中一共展示了DumperOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
private YamlConversionResult convert(Map<String, Collection<String>> properties) {
	if (properties.isEmpty()) {
		return YamlConversionResult.EMPTY;
	}

	YamlBuilder root = new YamlBuilder(mode, keyspaceList, status, YamlPath.EMPTY);
	for (Entry<String, Collection<String>> e : properties.entrySet()) {
		for (String v : e.getValue()) {
			root.addProperty(YamlPath.fromProperty(e.getKey()), v);
		}
	}

	Object object = root.build();

	DumperOptions options = new DumperOptions();
	options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
	options.setPrettyFlow(true);

	Yaml yaml = new Yaml(options);
	String output = yaml.dump(object);
	return new YamlConversionResult(status, output);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:23,代码来源:DefaultYamlConverter.java

示例2: initialValue

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
@Override
protected Yaml initialValue()
{
    Representer representer = new Representer() {
        {
            representers.put(Configuration.class, new Represent() {
                @Override
                public Node representData(Object data)
                {
                    return represent(((Configuration) data).self);
                }
            });
        }
    };

    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

    return new Yaml(new Constructor(), representer, options);
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:21,代码来源:YamlConfiguration.java

示例3: YamlSnakeYaml

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
public YamlSnakeYaml() {

		// Representer
		ExtensibleRepresenter representer = new ExtensibleRepresenter();

		// Install Java / Apache Cassandra serializers
		addDefaultSerializers(representer);

		// Install MongoDB / BSON serializers
		tryToAddSerializers("io.datatree.dom.adapters.YamlSnakeYamlBsonSerializers", representer);

		// Create flow-style YAML mapper
		DumperOptions optionsNormal = new DumperOptions();
		optionsNormal.setDefaultFlowStyle(FlowStyle.FLOW);
		mapper = new Yaml(representer, optionsNormal);

		// Create "pretty" YAML mapper
		DumperOptions optionsPretty = new DumperOptions();
		optionsPretty.setDefaultFlowStyle(FlowStyle.BLOCK);
		prettyMapper = new Yaml(representer, optionsPretty);
	}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:22,代码来源:YamlSnakeYaml.java

示例4: reload

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void reload() {
	Config.createConfigFile(this.file);

	DumperOptions dumperOptions = new DumperOptions();
	dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
	Yaml yaml = new Yaml(dumperOptions);
	try {
		this.list = yaml.loadAs(Utils.readFile(file), Map.class);
	} catch (IOException e) {
		e.printStackTrace();
	}

	if (this.list == null) {
		this.list = useSynchronization ? new Hashtable<>() : new HashMap<>();
	} else {
		this.list = useSynchronization ? new Hashtable<>(this.list) : new HashMap<>(this.list);
	}
}
 
开发者ID:Him188,项目名称:JPRE,代码行数:21,代码来源:YamlConfig.java

示例5: saveToString

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
@Override
public String saveToString() {
    yamlOptions.setIndent(options().indent());
    yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    yamlOptions.setAllowUnicode(SYSTEM_UTF);
    yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

    String header = buildHeader();
    String dump = yaml.dump(getValues(false));

    if (dump.equals(BLANK_CONFIG)) {
        dump = "";
    }

    return header + dump;
}
 
开发者ID:avaire,项目名称:avaire,代码行数:17,代码来源:YamlConfiguration.java

示例6: newYaml

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
public static Yaml newYaml() {
  PropertyUtils propertyUtils = new AdvancedPropertyUtils();
  propertyUtils.setSkipMissingProperties(true);

  Constructor constructor = new Constructor(Federations.class);
  TypeDescription federationDescription = new TypeDescription(Federations.class);
  federationDescription.putListPropertyType("federatedMetaStores", FederatedMetaStore.class);
  constructor.addTypeDescription(federationDescription);
  constructor.setPropertyUtils(propertyUtils);

  Representer representer = new AdvancedRepresenter();
  representer.setPropertyUtils(new FieldOrderPropertyUtils());
  representer.addClassTag(Federations.class, Tag.MAP);
  representer.addClassTag(AbstractMetaStore.class, Tag.MAP);
  representer.addClassTag(WaggleDanceConfiguration.class, Tag.MAP);
  representer.addClassTag(YamlStorageConfiguration.class, Tag.MAP);
  representer.addClassTag(GraphiteConfiguration.class, Tag.MAP);

  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setIndent(2);
  dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);

  return new Yaml(constructor, representer, dumperOptions);
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:25,代码来源:YamlFactory.java

示例7: newYaml

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
private static Yaml newYaml() {
    return new Yaml(new Constructor(),
                    new Representer(),
                    new DumperOptions(),
                    new Resolver() {
                        @Override
                        public Tag resolve(NodeId kind, String value, boolean implicit) {
                            if (value != null) {
                                if (value.equalsIgnoreCase("on") ||
                                        value.equalsIgnoreCase("off") ||
                                        value.equalsIgnoreCase("yes") ||
                                        value.equalsIgnoreCase("no")) {
                                    return Tag.STR;
                                }
                            }
                            return super.resolve(kind, value, implicit);
                        }
                    });
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:20,代码来源:ConfigViewFactory.java

示例8: testLoadBeanWithAutoFlow

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
/**
 * !!timestamp must be used, without it the implicit tag will be ignored
 * because 'date' is the JavaBean property.
 * 
 * Since the timestamp contains ':' character it cannot use plain scalar
 * style in the FLOW mapping style. Emitter suggests single quoted scalar
 * style and that is why the explicit '!!timestamp' is present in the YAML
 * document.
 * 
 * @see <a href="http://code.google.com/p/snakeyaml/issues/detail?id=128"></a>
 * 
 */
public void testLoadBeanWithAutoFlow() {
    MyBean bean = new MyBean();
    bean.setId("id123");
    DateTime etalon = new DateTime(timestamp, DateTimeZone.UTC);
    bean.setDate(etalon);
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.AUTO);
    Yaml dumper = new Yaml(new JodaTimeRepresenter(), options);
    String doc = dumper.dump(bean);
    // System.out.println(doc);
    assertEquals(
            "!!examples.jodatime.MyBean {date: !!timestamp '2001-09-09T01:46:40Z', id: id123}\n",
            doc);
    Yaml loader = new Yaml(new JodaTimeImplicitContructor());
    MyBean parsed = (MyBean) loader.load(doc);
    assertEquals(etalon, parsed.getDate());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:30,代码来源:JodaTimeFlowStylesTest.java

示例9: toString

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
@Override
public String toString() {
    Map<String,Object> data = new LinkedHashMap<String,Object>() {{
        if (asset != null) {
            put(ASSET, asset);
        }
        put(MAIN_CLASS, mainClass);
        put(HOLLOW, hollow);
        put(PROPERTIES, properties);
        put(MODULES, bootstrapModules);
        put(BOOTSTRAP_ARTIFACTS, bootstrapArtifacts);
        put(BUNDLE_DEPENDENCIES, bundleDependencies);
        put(DEPENDENCIES, dependencies);
    }};

    DumperOptions options = new DumperOptions();
    options.setPrettyFlow(true);
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);

    return yaml.dump(data);
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:23,代码来源:WildFlySwarmManifest.java

示例10: testEmitWithTags

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
public void testEmitWithTags() {
    TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
    DumperOptions options = new DumperOptions();
    options.setExplicitStart(true);
    Representer repr = new Representer();
    repr.addClassTag(TestObject.class, new Tag("!ruby/object:Test::Module::Object"));
    repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
    repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
    Yaml yaml2 = new Yaml(repr, options);
    String output = yaml2.dump(result);
    // System.out.println(output);
    assertTrue("Tags must be present.",
            output.startsWith("--- !ruby/object:Test::Module::Object"));
    assertTrue("Tags must be present: " + output,
            output.contains("!ruby/object:Test::Module::Sub1"));
    assertTrue("Tags must be present.", output.contains("!ruby/object:Test::Module::Sub2"));
    // parse back.
    TestObject result2 = parseObject(output);
    assertEquals(0, result2.getSub1().getAtt2());
    assertEquals("MyString", result2.getSub2().getAtt1());
    assertEquals(1, result2.getSub2().getAtt2().size());
    assertEquals(12345, result2.getSub2().getAtt3());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:24,代码来源:RubyTest.java

示例11: testDate

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
public void testDate() {
    List<Date> list = new ArrayList<Date>();
    list.add(new Date(1229684761159L));
    list.add(new Date(1229684761059L));
    list.add(new Date(1229684761009L));
    list.add(new Date(1229684761150L));
    list.add(new Date(1229684761100L));
    list.add(new Date(1229684761000L));
    list.add(new Date(1229684760000L));
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(list);
    assertEquals(
            "- 2008-12-19T11:06:01.159Z\n- 2008-12-19T11:06:01.059Z\n- 2008-12-19T11:06:01.009Z\n- 2008-12-19T11:06:01.150Z\n- 2008-12-19T11:06:01.100Z\n- 2008-12-19T11:06:01Z\n- 2008-12-19T11:06:00Z\n",
            output);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:18,代码来源:SafeRepresenterTest.java

示例12: testStyle2

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
public void testStyle2() {
    List<Integer> list = new ArrayList<Integer>();
    list.add(new Integer(1));
    list.add(new Integer(1));
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("age", 5);
    map.put("name", "Ubuntu");
    map.put("list", list);
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(DumperOptions.ScalarStyle.SINGLE_QUOTED);
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    assertEquals("{'age': !!int '5', 'name': 'Ubuntu', 'list': [!!int '1', !!int '1']}\n",
            output);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:17,代码来源:SafeRepresenterTest.java

示例13: testStyle2Pretty

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
public void testStyle2Pretty() {
    List<Integer> list = new ArrayList<Integer>();
    list.add(new Integer(1));
    list.add(new Integer(1));
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    map.put("age", 5);
    map.put("name", "Ubuntu");
    map.put("list", list);
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(DumperOptions.ScalarStyle.SINGLE_QUOTED);
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
    options.setPrettyFlow(true);
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(map);
    assertEquals(
            "{\n  'age': !!int '5',\n  'name': 'Ubuntu',\n  'list': [\n    !!int '1',\n    !!int '1']\n  \n}\n",
            output);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:19,代码来源:SafeRepresenterTest.java

示例14: testEmitQuoted

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
/**
 * http://pyyaml.org/ticket/196
 */
public void testEmitQuoted() {
    List<String> list = new ArrayList<String>(3);
    list.add("This is an 'example'.");
    list.add("This is an \"example\".");
    list.add("123");
    String output = dump(list);
    assertEquals("[This is an 'example'., This is an \"example\"., '123']\n", output);
    // single quoted
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(ScalarStyle.SINGLE_QUOTED);
    Yaml yaml = new Yaml(options);
    String output2 = yaml.dump(list);
    // System.out.println(output2);
    assertEquals("- 'This is an ''example''.'\n- 'This is an \"example\".'\n- '123'\n", output2);
    // double quoted
    DumperOptions options2 = new DumperOptions();
    options2.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
    yaml = new Yaml(options2);
    String output3 = yaml.dump(list);
    // System.out.println(output2);
    assertEquals("- \"This is an 'example'.\"\n- \"This is an \\\"example\\\".\"\n- \"123\"\n",
            output3);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:27,代码来源:StrTagTest.java

示例15: testCustomGenerator

import org.yaml.snakeyaml.DumperOptions; //导入依赖的package包/类
public void testCustomGenerator() {
    List<Object> list = new ArrayList<Object>();
    list.add("data123");
    list.add(list);
    Yaml yaml1 = new Yaml();
    String output = yaml1.dump(list);
    assertEquals("&id001\n" +
            "- data123\n" +
            "- *id001\n", output);


    DumperOptions options = new DumperOptions();
    Yaml yaml2 = new Yaml(options);
    options.setAnchorGenerator(new Gener(3));
    String output2 = yaml2.dump(list);
    assertEquals("&list-id004\n" +
            "- data123\n" +
            "- *list-id004\n", output2);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:20,代码来源:AnchorGeneratorTest.java


注:本文中的org.yaml.snakeyaml.DumperOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。