本文整理汇总了Java中org.ho.yaml.Yaml.dump方法的典型用法代码示例。如果您正苦于以下问题:Java Yaml.dump方法的具体用法?Java Yaml.dump怎么用?Java Yaml.dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ho.yaml.Yaml
的用法示例。
在下文中一共展示了Yaml.dump方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Configuration
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public Configuration(File file) {
this.file = file;
Map<String, Object> configTemp;
try {
configTemp = Yaml.loadType(file, LinkedHashMap.class);
} catch (Exception e) {
configTemp = new HashMap<>();
if (file.equals(CONFIG_FILE)) {
for (ConfigKey configKey : ConfigKey.values()) {
configTemp.put(configKey.name(), configKey.value());
}
logger.error("can't load config {}", e.getMessage());
try {
logger.info("Creating default config");
Yaml.dump(configTemp, file);
} catch (FileNotFoundException ee) {
logger.warn("Error saving config", ee);
}
}
}
config = configTemp;
}
示例2: testDateArray
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* Test that the parser can save/load an array of formatted dates
*
* @author Steve Leach
*/
public void testDateArray()
{
YamlConfig.getDefaultConfig().setDateFormat(DateWrapper.DATEFORMAT_YAML);
Date[] dates = new Date[3];
dates[0] = TestDateTimeParser.getDate( 2004, 10, 01, 10, 35, 21 );
dates[1] = TestDateTimeParser.getDate( 1900, 01, 10, 10, 35, 21 );
dates[2] = TestDateTimeParser.getDate( 1940, 04, 04, 0, 0, 0 );
String s = Yaml.dump(dates,true);
Date[] dates2 = Yaml.loadType( s, Date[].class );
YamlConfig.getDefaultConfig().setDateFormat(null);
for (int i = 0; i < dates.length; i++)
{
assertEquals( dates[i], dates2[i], TestDateTimeParser.DELTA_30SEC );
}
}
示例3: testDatesInBeans
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* Test that the parser can load formatted dates when embedded in JavaBeans
*
* @author Steve Leach
*/
public void testDatesInBeans() {
YamlConfig.getDefaultConfig().setDateFormat(DateWrapper.DATEFORMAT_YAML);
Date d1 = TestDateTimeParser.getDate( 1965, 10, 01, 0, 0, 0 );
Person bob = new Person();
bob.setName("Bob");
bob.setBirthDate(d1);
Company anyCorp = new Company();
anyCorp.setName("AnyCorp");
anyCorp.setPresident(bob);
String s = Yaml.dump(anyCorp,true);
Company company = Yaml.loadType( s, Company.class );
Person president = company.getPresident();
assertEquals( bob.getBirthDate(), president.getBirthDate(), TestDateTimeParser.DELTA_30SEC );
YamlConfig.getDefaultConfig().setDateFormat(null);
}
示例4: 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"));
}
});
}
示例5: saveConfig
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* Dump in-memory configuration to the config file
*/
public void saveConfig() {
try {
Yaml.dump(config, file);
} catch (FileNotFoundException e) {
logger.warn("Error saving config", e);
}
}
示例6: 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);
}
示例7: testBreakLineCharacters
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testBreakLineCharacters() throws Exception{
Person john = new Person();
String name = "John \n Smith";
john.setName(name);
assertEquals(name, john.getName());
File dumpfile = new File("yml/john_smith.yml");
Yaml.dump(john, dumpfile);
Person john2 = (Person) Yaml.loadType(dumpfile, Person.class);
System.out.println(john2.getName());
System.out.println(john.getName());
assertEquals(john.getName(), john2.getName());
}
示例8: testEmptyLinkedLists
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testEmptyLinkedLists(){
Map map = new HashMap();
LinkedList list = new LinkedList();
map.put("my_list", list);
String yamlString = Yaml.dump(map, false);
Object obj = Yaml.load(yamlString);
}
示例9: 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());
}
示例10: testKeysNotStrings
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testKeysNotStrings(){
Map map = new HashMap();
map.put(13, "value1");
String yamlText = Yaml.dump(map, true);
System.out.println(yamlText);
}
示例11: save
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* @see com.ziroby.dmassist.model.EntityListWithSave#save(java.io.File)
*/
public void save(File file) throws FileNotFoundException {
Yaml.dump(getEntities(), file, true);
}
示例12: testDateParserYaml
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* Test that the parser can load dates when saved in YAML format (with spaces)
*
* @author Steve Leach
*/
public void testDateParserYaml() {
YamlConfig.getDefaultConfig().setDateFormat(DateWrapper.DATEFORMAT_YAML);
Date d1 = TestDateTimeParser.getDate( 2004, 10, 01, 10, 35, 21 );
String s = Yaml.dump(d1,true);
Date d2 = Yaml.loadType( s, Date.class );
assertEquals( d1, d2, TestDateTimeParser.DELTA_30SEC );
YamlConfig.getDefaultConfig().setDateFormat(null);
}
示例13: testDateParserIso
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* Test that the parser can load dates when saved in ISO 8601 format
*
* @author Steve Leach
*/
public void testDateParserIso() {
YamlConfig.getDefaultConfig().setDateFormat(DateWrapper.DATEFORMAT_ISO8601);
Date d1 = TestDateTimeParser.getDate( 2004, 10, 01, 10, 35, 21 );
String s = Yaml.dump(d1,true);
Date d2 = Yaml.loadType( s, Date.class );
assertEquals( d1, d2, TestDateTimeParser.DELTA_30SEC );
YamlConfig.getDefaultConfig().setDateFormat(null);
}
示例14: testSaveLoadDateConfig
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
/**
* Tests that the YamlConfig is correctly saved/loaded, including the date format
*
* @author Steve Leach
*/
public void testSaveLoadDateConfig() throws FileNotFoundException {
YamlConfig.getDefaultConfig().setDateFormat(DateWrapper.DATEFORMAT_YAML);
File file = new File("yml/testConfig.yml");
Yaml.dump( YamlConfig.getDefaultConfig(), file );
YamlConfig config = Yaml.loadType( file, YamlConfig.class );
assertEquals( YamlConfig.getDefaultConfig().getDateFormat(), config.getDateFormat() );
YamlConfig.getDefaultConfig().setDateFormat(null);
}
示例15: testPhoneNumber
import org.ho.yaml.Yaml; //导入方法依赖的package包/类
public void testPhoneNumber()
{
String number = "19171234567";
String dump = Yaml.dump(number);
System.out.println(dump);
Object o = Yaml.load(dump);
assertEquals(String.class, o.getClass());
assertEquals(o, number);
}