本文整理汇总了Java中org.ho.yaml.Yaml.load方法的典型用法代码示例。如果您正苦于以下问题:Java Yaml.load方法的具体用法?Java Yaml.load怎么用?Java Yaml.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ho.yaml.Yaml
的用法示例。
在下文中一共展示了Yaml.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testThreeSlashesAtTheEnd
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testThreeSlashesAtTheEnd(){
final String slashes="ghghghg hj hkl; \\\\\\";
Map amap=new HashMap();
amap.put("key", slashes);
String dump = Yaml.dump(amap);
System.out.println(dump);
Object o = Yaml.load(dump);
System.out.println(o);
integrationTest(amap, "testThreeSlashesAtTheEnd", new Validator<Map>(){
public void validate(Map m){
assertEquals(slashes, m.get("key"));
}
});
}
示例2: load
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* 读取配置文件
* <br><i>at 2014年7月12日下午4:36:36</i>
* @author lichee
* @see <a href="http://nicecoder.net">nicecoder.net</a>
* @param path
*/
@SuppressWarnings("unchecked")
public void load(String path){
try {
File config = new File(path);
meta = (Map<String, String>) Yaml.load(config);
setMeta(meta);
setAuthor(meta.get("author"));
setName(meta.get("name"));
setVersion(meta.get("version"));
//路径设置
absRootDir = PathUtil.subFileName(config.getAbsolutePath());
postsDir = absRootDir+postsDir;
outputDir = absRootDir+outputDir;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
示例3: ConfigFile
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* Constructor
*/
public ConfigFile(boolean debug) {
_availableTopics = new ArrayList<>();
try {
Map<String, Object> map = (Map<String, Object>) Yaml.load(new File(CONFIG_FILE_PATH));
/* Production Config */
_sections = (Map<String, Object>) map.get("sections");
for (Object value : _sections.values()) {
Map<String, Object> config = (Map<String, Object>) value;
_availableTopics.add(config.get("input_topic").toString());
if (config.get("output_topic") != null) {
_availableTopics.add(config.get("output_topic").toString());
}
if (debug) {
System.out.println("Select section: " + value.toString());
System.out.println(" - inputTopic: [" + config.get("input_topic") + "]");
System.out.println(" - outputTopic: [" + config.get("output_topic") + "]");
System.out.println(" - zkConnect: [" + config.get("zk_connect") + "]");
}
}
/* General Config */
_general = (Map<String, Object>) map.get("general");
} catch (FileNotFoundException e) {
Logger.getLogger(ConfigFile.class.getName()).log(Level.SEVERE, "config file not found");
}
}
示例4: testSequenceMapBug2Strange
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testSequenceMapBug2Strange(){
String s = "players:\r\n"+
" -\r\n"+
" name: Mark McGwire\r\n" +
" -\r\n"+
" name: Sammy Sosa\r\n";
Map m = (Map)Yaml.load(s);
System.out.println(m);
List players = (List)m.get("players");
assertEquals(2, players.size());
Map mm = (Map)players.get(0);
assertEquals("Mark McGwire", mm.get("name"));
Map ss = (Map)players.get(1);
assertEquals("Sammy Sosa", ss.get("name"));
}
示例5: main
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public static void main(String[] args) {
String s = "---\n a: cat\n dog:\n - loyal\n - friendly\n - furry\n";
System.out.println(s);
Map a = (Map)Yaml.load(s);
System.out.println("This should print loyal: " + ((List)a.get("dog")).get(0));
String s2 = Yaml.dump(a);
System.out.println("Here is the object encoded back to a YAML string:");
System.out.println(s2);
}
示例6: testOneSpaceIndent
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testOneSpaceIndent(){
String yamlText =
"---\n" +
"one: \n" +
" - 1\n" +
" - 2\n";
Map m = (Map)Yaml.load(yamlText);
assertEquals(1, ((List)m.get("one")).get(0));
assertEquals(2, ((List)m.get("one")).get(1));
}
示例7: testLargeDocument
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testLargeDocument() throws Exception {
File f = new File("yml/testLargeDocument.yml");
Map m = new HashMap();
List largeList = new ArrayList();
for (int i = 0; i < 100000; i++)
largeList.add(i);
m.put("large list", largeList);
Yaml.dump(m, f);
Map result = (Map)Yaml.load(f);
assertEquals(100000, ((List)m.get("large list")).size());
}
示例8: testBadTabMap
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testBadTabMap() throws Exception{
try {
Yaml.load(new File("bad_yaml/bad_tab_map.yml"));
} catch (YamlException e) {
assertEquals("Error near line 2: Tabs may not be used for indentation.", e.getMessage());
return;
}
throw new RuntimeException("Should have failed.");
}
示例9: testBadYaml
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testBadYaml() throws Exception{
try {
Yaml.load(new File("bad_yaml/bad_yaml.yml"));
} catch (YamlException e) {
assertEquals("Error near line 14: Tabs may not be used for indentation.", e.getMessage());
return;
}
throw new RuntimeException("Should have failed.");
}
示例10: testGrails
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testGrails() throws Exception{
try {
Yaml.load(new File("bad_yaml/grails.yml"));
} catch (YamlException e) {
assertEquals("Error near line 22: Can't create object of type class java.util.HashMap$Values using default constructor.", e.getMessage());
return;
}
throw new RuntimeException("Should have failed.");
}
示例11: testSkimoNegativeInList
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testSkimoNegativeInList(){
String yamlText =
"---\n" +
"prefix:\n" +
" - 1\n" +
" - -1\n" +
" - 1";
Map map = (Map)Yaml.load(yamlText);
assertEquals(-1, ((List)map.get("prefix")).get(1));
}
示例12: testOneLineMaps2
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testOneLineMaps2(){
String yamlText =
"---\n" +
"one:\n" +
" - 1\n" +
" - one: two\n";
Map m = (Map)Yaml.load(yamlText);
assertEquals("two", ((Map)((List)m.get("one")).get(1)).get("one"));
}
示例13: testNnumberAsKey
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testNnumberAsKey(){
String yamlText =
"---\n" +
"1: -1.5";
Map m = (Map)Yaml.load(yamlText);
System.out.println(m);
assertEquals(-1.5, m.get(1));
}
示例14: testShouldBeBadValuesInList
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testShouldBeBadValuesInList(){
try {
String yamlText =
"- one\n" +
"one\n" +
"two\n";
Object m = Yaml.load(yamlText);
System.out.println(m);
YamlParser.parse(yamlText);
} catch (YamlException e) {
e.printStackTrace();
return;
}
throw new RuntimeException("Should have failed.");
}
示例15: testComment2
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testComment2(){
String s = "players:\n"+
" -\n"+
" name: Mark McGwire\n"+
" hr: 65\n"+
" avg: 0.278\n"+
" #hutseoahtusehotshuc.chcuseoa\n" +
" -\n"+
" name: Sammy Sosa\n"+
" hr: 63\n"+
" avg: 0.288\n";
Map m = (Map)Yaml.load(s);
System.out.println(m);
}