本文整理匯總了Java中org.yaml.snakeyaml.DumperOptions.setDefaultScalarStyle方法的典型用法代碼示例。如果您正苦於以下問題:Java DumperOptions.setDefaultScalarStyle方法的具體用法?Java DumperOptions.setDefaultScalarStyle怎麽用?Java DumperOptions.setDefaultScalarStyle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.yaml.snakeyaml.DumperOptions
的用法示例。
在下文中一共展示了DumperOptions.setDefaultScalarStyle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testStyle
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testStyle() {
List<Integer> list = new ArrayList<Integer>();
list.add(new Integer(1));
list.add(new Integer(1));
Map<String, Object> map = new HashMap<String, Object>();
map.put("list", list);
map.put("name", "Ubuntu");
map.put("age", 5);
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
String output = yaml.dump(map);
assertTrue(output.contains("\"age\": !!int \"5\""));
assertTrue(output.contains("\"name\": \"Ubuntu\""));
assertTrue(output.contains("- !!int \"1\""));
}
示例2: 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);
}
示例3: testSplitLineExpectFlowSequenceItem
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testSplitLineExpectFlowSequenceItem() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
options.setWidth(8);
Yaml yaml;
String output;
// Split lines enabled (default)
yaml = new Yaml(options);
output = yaml.dump(Arrays.asList("1111111111", "2222222222"));
assertEquals("[\"1111111111\",\n \"2222222222\"]\n", output);
output = yaml.dump(Arrays.asList("1", "2"));
assertEquals("[\"1\", \"2\"]\n", output);
// Split lines disabled
options.setSplitLines(false);
assertFalse(options.getSplitLines());
yaml = new Yaml(options);
output = yaml.dump(Arrays.asList("1111111111", "2222222222"));
assertEquals("[\"1111111111\", \"2222222222\"]\n", output);
output = yaml.dump(Arrays.asList("1", "2"));
assertEquals("[\"1\", \"2\"]\n", output);
}
示例4: 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);
}
示例5: testDumperOptionsStyle
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testDumperOptionsStyle() {
List<Integer> data = new ArrayList<Integer>();
for (int i = 0; i < 5; i++) {
data.add(i);
}
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
Yaml yaml = new Yaml(options);
String output = yaml.dump(data);
assertTrue(output.contains("- !!int \"0\""));
assertTrue(output.contains("- !!int \"1\""));
assertTrue(output.contains("- !!int \"4\""));
}
示例6: yamlParser
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
@Bean
Yaml yamlParser() {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
return new Yaml(options);
}
示例7: testDoubleQuotedStyle
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testDoubleQuotedStyle() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
Yaml yaml = new Yaml(options);
String output = yaml.dump("í");
// System.out.println(output);
assertEquals("\"í\"\n", output);
}
示例8: testDoubleQuotedStyle
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testDoubleQuotedStyle() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
options.setWidth(20);
options.setIndent(4);
Yaml yaml = new Yaml(options);
String etalon = "12345678901234567890\n\n123 456";
String output = yaml.dump(etalon);
// System.out.println(output);
assertEquals("\"12345678901234567890\\n\\\n \\n123 456\"\n", output);
String parsed = (String) yaml.load(output);
assertEquals(etalon, parsed);
}
示例9: testDoubleQuotedStyleNoLineSplit
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testDoubleQuotedStyleNoLineSplit() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(ScalarStyle.DOUBLE_QUOTED);
options.setWidth(20);
options.setSplitLines(false);
options.setIndent(4);
Yaml yaml = new Yaml(options);
String etalon = "12345678901234567890\n\n123 456";
String output = yaml.dump(etalon);
// System.out.println(output);
assertEquals("\"12345678901234567890\\n\\n123 456\"\n", output);
String parsed = (String) yaml.load(output);
assertEquals(etalon, parsed);
}
示例10: testLong
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testLong() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(ScalarStyle.FOLDED);
Yaml yaml = new Yaml(options);
String result = yaml
.dump("qqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq "
+ "qqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq "
+ "qqqqqqqqqqqqqqqqqqqqqqqqq 111111111111111111111111\n "
+ "qqqqqqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqq\n");
// System.out.println(result);
assertTrue(result.startsWith(">\n"));
assertEquals(
">\n qqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqq\n qqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqq 111111111111111111111111\n qqqqqqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqq\n",
result);
}
示例11: newYaml
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
private static Yaml newYaml(boolean useSingleQuotes) {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setAllowUnicode(true);
if (useSingleQuotes) {
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.SINGLE_QUOTED);
}
return new Yaml(options);
}
示例12: initialValue
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
@Override
protected Yaml initialValue() {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
return new Yaml(options);
}
示例13: testLong
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
/**
* test fix for issue 18 -
* http://code.google.com/p/snakeyaml/issues/detail?id=18
*/
public void testLong() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
Yaml yaml = new Yaml(options);
Foo foo = new Foo();
String output = yaml.dump(foo);
// System.out.println(output);
Foo foo2 = (Foo) yaml.load(output);
assertEquals(new Long(42L), foo2.getBar());
}
示例14: testWriteFolded
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testWriteFolded() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(ScalarStyle.FOLDED);
String folded = "0123456789 0123456789\n0123456789 0123456789";
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("aaa", folded);
map.put("bbb", "\nbla-bla\n");
Yaml yaml = new Yaml(options);
String output = yaml.dump(map);
String etalon = "\"aaa\": >-\n 0123456789 0123456789\n\n 0123456789 0123456789\n\"bbb\": >2\n\n bla-bla\n";
assertEquals(etalon, output);
}
示例15: testWriteLiteral
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testWriteLiteral() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(ScalarStyle.LITERAL);
String folded = "0123456789 0123456789 0123456789 0123456789";
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("aaa", folded);
map.put("bbb", "\nbla-bla\n");
Yaml yaml = new Yaml(options);
String output = yaml.dump(map);
String etalon = "\"aaa\": |-\n 0123456789 0123456789 0123456789 0123456789\n\"bbb\": |2\n\n bla-bla\n";
assertEquals(etalon, output);
}