本文整理汇总了Java中org.yaml.snakeyaml.DumperOptions.setDefaultFlowStyle方法的典型用法代码示例。如果您正苦于以下问题:Java DumperOptions.setDefaultFlowStyle方法的具体用法?Java DumperOptions.setDefaultFlowStyle怎么用?Java DumperOptions.setDefaultFlowStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.DumperOptions
的用法示例。
在下文中一共展示了DumperOptions.setDefaultFlowStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: addServerId
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public static void addServerId(String serverId) throws IOException {
FileWriter writer = new FileWriter(ConfigurationConstants.CONFIG_FILE_NAME);
DumperOptions options=new DumperOptions();
options.setIndent(1);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml=new Yaml(new NullRepresenter(),options);
String conf = yaml.dump(configuration);
yaml.dump(conf, writer);
//remove |- literal from the config file
File file = new File(ConfigurationConstants.CONFIG_FILE_NAME);
String s1 = FileUtils.readFileToString(file);
String substring = s1.substring(1, s1.length() - 1);
FileUtils.writeStringToFile(file,substring);
}
示例4: configYamlFormat
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
private static void configYamlFormat(final ToolBelt belt, final AppConfig config) {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(
"BLOCK".equalsIgnoreCase(config.getString("RD_YAML_FLOW", "BLOCK")) ?
DumperOptions.FlowStyle.BLOCK :
DumperOptions.FlowStyle.FLOW
);
dumperOptions.setPrettyFlow(config.getBool("RD_YAML_PRETTY", true));
Representer representer = new Representer();
representer.addClassTag(JobItem.class, Tag.MAP);
representer.addClassTag(ScheduledJobItem.class, Tag.MAP);
representer.addClassTag(DateInfo.class, Tag.MAP);
representer.addClassTag(Execution.class, Tag.MAP);
belt.formatter(new YamlFormatter(representer, dumperOptions));
belt.channels().infoEnabled(false);
belt.channels().warningEnabled(false);
belt.channels().errorEnabled(false);
}
示例5: 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);
}
示例6: 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);
}
示例7: testWriteMultiLineList
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testWriteMultiLineList() {
String one = "first\nsecond\nthird";
String two = "one\ntwo\nthree\n";
byte[] binary = { 8, 14, 15, 10, 126, 32, 65, 65, 65 };
List<Object> list = new ArrayList<Object>(2);
list.add(one);
list.add(two);
list.add(binary);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
String output = yaml.dump(list);
// System.out.println(output);
String etalon = "- |-\n first\n second\n third\n- |\n one\n two\n three\n- !!binary |-\n CA4PCn4gQUFB\n";
assertEquals(etalon, output);
@SuppressWarnings("unchecked")
List<Object> parsed = (List<Object>) yaml.load(etalon);
assertEquals(3, parsed.size());
assertEquals(one, parsed.get(0));
assertEquals(two, parsed.get(1));
assertEquals(new String(binary), new String((byte[]) parsed.get(2)));
}
示例8: 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 );
}
示例9: getYaml
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public static Yaml getYaml() {
final DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
options.setPrettyFlow(true);
SkipNullRepresenter representer = new SkipNullRepresenter();
representer.addClassTag(TestDefAction.class, Tag.MAP);
return new Yaml(representer, options);
}
示例10: reloadConfig
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
@Override
public void reloadConfig() {
this.config = new Config(this.configFile);
InputStream configStream = this.getResource("config.yml");
if (configStream != null) {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
try {
this.config.setDefault(yaml.loadAs(Utils.readFile(this.configFile), LinkedHashMap.class));
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
}
示例11: parseContent
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
private void parseContent(String content) {
switch (this.type) {
case Config.PROPERTIES:
this.parseProperties(content);
break;
case Config.JSON:
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
this.config = new ConfigSection(gson.fromJson(content, new TypeToken<LinkedHashMap<String, Object>>() {
}.getType()));
break;
case Config.YAML:
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
this.config = new ConfigSection(yaml.loadAs(content, LinkedHashMap.class));
if (this.config == null) {
this.config = new ConfigSection();
}
break;
// case Config.SERIALIZED
case Config.ENUM:
this.parseList(content);
break;
default:
this.correct = false;
}
}
示例12: createSimplePackage
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
private Package createSimplePackage() throws IOException {
Package pkg = new Package();
// Add package metadata
PackageMetadata packageMetadata = new PackageMetadata();
packageMetadata.setName("myapp");
packageMetadata.setVersion("1.0.0");
packageMetadata.setMaintainer("bob");
pkg.setMetadata(packageMetadata);
// Add ConfigValues
Map<String, String> map = new HashMap<>();
map.put("foo", "bar");
map.put("fiz", "faz");
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
dumperOptions.setPrettyFlow(true);
Yaml yaml = new Yaml(dumperOptions);
ConfigValues configValues = new ConfigValues();
configValues.setRaw(yaml.dump(map));
pkg.setConfigValues(configValues);
// Add template
Resource resource = new ClassPathResource("/org/springframework/cloud/skipper/io/generic-template.yml");
String genericTempateData = StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset());
Template template = new Template();
template.setData(genericTempateData);
template.setName(resource.getURL().toString());
List<Template> templateList = new ArrayList<>();
templateList.add(template);
pkg.setTemplates(templateList);
return pkg;
}
示例13: save
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
@Override
public void save() {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
try {
Utils.writeFile(file, yaml.dump(this.list));
} catch (IOException e) {
e.printStackTrace();
}
}
示例14: save
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public boolean save(Boolean async) {
if (this.file == null) throw new IllegalStateException("Failed to save Config. File object is undefined.");
if (this.correct) {
String content = "";
switch (this.type) {
case Config.PROPERTIES:
content = this.writeProperties();
break;
case Config.JSON:
content = new GsonBuilder().setPrettyPrinting().create().toJson(this.config);
break;
case Config.YAML:
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
content = yaml.dump(this.config);
break;
case Config.ENUM:
for (Object o : this.config.entrySet()) {
Map.Entry entry = (Map.Entry) o;
content += String.valueOf(entry.getKey()) + "\r\n";
}
break;
}
if (async) {
Server.getInstance().getScheduler().scheduleAsyncTask(new FileWriteTask(this.file, content));
} else {
try {
Utils.writeFile(this.file, content);
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
return true;
} else {
return false;
}
}
示例15: toYaml
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
private String toYaml(Object obj) {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setIndent(4);
return new Yaml(options).dump(obj);
}