本文整理匯總了Java中org.yaml.snakeyaml.DumperOptions.setWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java DumperOptions.setWidth方法的具體用法?Java DumperOptions.setWidth怎麽用?Java DumperOptions.setWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.yaml.snakeyaml.DumperOptions
的用法示例。
在下文中一共展示了DumperOptions.setWidth方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDumperOptions
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testDumperOptions() {
List<Integer> data = new ArrayList<Integer>();
for (int i = 0; i < 50; i++) {
data.add(i);
}
Yaml yaml = new Yaml();
String output = yaml.dump(data);
assertTrue(output.contains("[0, 1, 2, 3, 4, 5, 6, 7, 8"));
//
DumperOptions options = new DumperOptions();
options.setWidth(50);
options.setIndent(4);
yaml = new Yaml(options);
output = yaml.dump(data);
assertTrue(output.contains("1, 2"));
}
示例2: testMatteBorder
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testMatteBorder() {
DumperOptions options = new DumperOptions();
options.setWidth(400);
Yaml yaml = new Yaml(new ImmutablesRepresenter(), options);
Insets insets = new Insets(10, 20, 30, 40);
Color color = new Color(100, 150, 200);
MatteBorder border = BorderFactory.createMatteBorder(insets.top, insets.left,
insets.bottom, insets.right, color);
String dump = yaml.dump(border);
assertEquals(
"!!javax.swing.border.MatteBorder [!!java.awt.Insets [10, 20, 30, 40], !!java.awt.Color [100, 150, 200, 255]]\n",
dump);
Object loaded = yaml.load(dump);
assertTrue(loaded instanceof MatteBorder);
MatteBorder loadedBorder = (MatteBorder) loaded;
assertEquals(insets, loadedBorder.getBorderInsets());
assertEquals(color, loadedBorder.getMatteColor());
}
示例3: testSplitLineExpectFirstFlowSequenceItem
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testSplitLineExpectFirstFlowSequenceItem() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
options.setWidth(8);
Yaml yaml;
String output;
Map<String, Object> map = new TreeMap<String, Object>();
map.put("12345", Arrays.asList("1111111111"));
// Split lines enabled (default)
yaml = new Yaml(options);
output = yaml.dump(map);
assertEquals("{\"12345\": [\n \"1111111111\"]}\n", output);
// Split lines disabled
options.setSplitLines(false);
assertFalse(options.getSplitLines());
yaml = new Yaml(options);
output = yaml.dump(map);
assertEquals("{\"12345\": [\"1111111111\"]}\n", output);
}
示例4: 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);
}
示例5: getYaml
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
private static Yaml getYaml() {
Representer representer = new TapeRepresenter();
representer.addClassTag(YamlTape.class, YamlTape.TAPE_TAG);
Constructor constructor = new TapeConstructor();
constructor.addTypeDescription(new TypeDescription(YamlTape.class, YamlTape.TAPE_TAG));
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(BLOCK);
dumperOptions.setWidth(256);
Yaml yaml = new Yaml(constructor, representer, dumperOptions);
yaml.setBeanAccess(BeanAccess.FIELD);
return yaml;
}
示例6: 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);
}
示例7: 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);
}
示例8: testNoFoldedScalar
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testNoFoldedScalar() {
DumperOptions options = new DumperOptions();
options.setWidth(30);
Yaml yaml = new Yaml(options);
String output = yaml.dump(getData());
// System.out.println(output);
String etalon = Util.getLocalResource("representer/scalar-style1.yaml");
assertEquals(etalon, output);
}
示例9: testCustomScalarStyle
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testCustomScalarStyle() {
DumperOptions options = new DumperOptions();
options.setWidth(30);
Yaml yaml = new Yaml(new MyRepresenter(), options);
String output = yaml.dump(getData());
// System.out.println(output);
String etalon = Util.getLocalResource("representer/scalar-style2.yaml");
assertEquals(etalon, output);
}
示例10: testCustomScalarStyleNoSplitLines
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testCustomScalarStyleNoSplitLines() {
DumperOptions options = new DumperOptions();
options.setWidth(30);
options.setSplitLines(false);
Yaml yaml = new Yaml(new MyRepresenter(), options);
String output = yaml.dump(getData());
// System.out.println(output);
String etalon = Util.getLocalResource("representer/scalar-style3.yaml");
assertEquals(etalon, output);
}
示例11: testJavaStackTraceWithNoSpecialCharacters
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testJavaStackTraceWithNoSpecialCharacters() {
DumperOptions options = new DumperOptions();
options.setWidth(50);
Yaml yaml = new Yaml(options);
String input = Util.getLocalResource("representer/stacktrace2.txt");
assertEquals(-1, input.indexOf(':'));
assertEquals(-1, input.indexOf('\t'));
String result = yaml.dump(input);
// System.out.println(result);
assertEquals(result, yaml.dump(yaml.load(result)));
}
示例12: testSplitLineExpectFirstFlowMappingKey
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testSplitLineExpectFirstFlowMappingKey() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
options.setWidth(16);
Yaml yaml;
String output;
Map<String, String> nonSplitMap = new TreeMap<String, String>();
nonSplitMap.put("3", "4");
Map<String, Map<String, String>> nonSplitContainerMap = new TreeMap<String, Map<String, String>>();
nonSplitContainerMap.put("1 2", nonSplitMap);
Map<String, String> splitMap = new TreeMap<String, String>();
splitMap.put("3333333333", "4444444444");
Map<String, Map<String, String>> splitContainerMap = new TreeMap<String, Map<String, String>>();
splitContainerMap.put("1111111111 2222222222", splitMap);
// Split lines enabled (default)
yaml = new Yaml(options);
output = yaml.dump(splitContainerMap);
assertEquals("{\"1111111111 2222222222\": {\n \"3333333333\": \"4444444444\"}}\n", output);
output = yaml.dump(nonSplitContainerMap);
assertEquals("{\"1 2\": {\"3\": \"4\"}}\n", output);
// Split lines disabled
options.setSplitLines(false);
assertFalse(options.getSplitLines());
yaml = new Yaml(options);
output = yaml.dump(splitContainerMap);
assertEquals("{\"1111111111 2222222222\": {\"3333333333\": \"4444444444\"}}\n", output);
output = yaml.dump(nonSplitContainerMap);
assertEquals("{\"1 2\": {\"3\": \"4\"}}\n", output);
}
示例13: testSplitLineExpectFlowMappingKey
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public void testSplitLineExpectFlowMappingKey() {
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
options.setWidth(16);
Yaml yaml;
String output;
Map<String, String> nonSplitMap = new TreeMap<String, String>();
nonSplitMap.put("1", "2");
nonSplitMap.put("3", "4");
Map<String, String> splitMap = new TreeMap<String, String>();
splitMap.put("1111111111", "2222222222");
splitMap.put("3333333333", "4444444444");
// Split lines enabled (default)
yaml = new Yaml(options);
output = yaml.dump(splitMap);
assertEquals("{\"1111111111\": \"2222222222\",\n \"3333333333\": \"4444444444\"}\n", output);
output = yaml.dump(nonSplitMap);
assertEquals("{\"1\": \"2\", \"3\": \"4\"}\n", output);
// Split lines disabled
options.setSplitLines(false);
assertFalse(options.getSplitLines());
yaml = new Yaml(options);
output = yaml.dump(splitMap);
assertEquals("{\"1111111111\": \"2222222222\", \"3333333333\": \"4444444444\"}\n", output);
output = yaml.dump(nonSplitMap);
assertEquals("{\"1\": \"2\", \"3\": \"4\"}\n", output);
}
示例14: toString
import org.yaml.snakeyaml.DumperOptions; //導入方法依賴的package包/類
public synchronized String toString() {
DumperOptions options = new DumperOptions();
options.setWidth(50);
options.setIndent(4);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
return yaml.dump(map);
}