當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。