本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
});
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}