当前位置: 首页>>代码示例>>Java>>正文


Java Yaml.dump方法代码示例

本文整理汇总了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;
}
 
开发者ID:imotSpot,项目名称:imotSpot,代码行数:25,代码来源:Configuration.java

示例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 );
    }
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:24,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:27,代码来源:IntegrationTests.java

示例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"));
            }
        });

    }
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:19,代码来源:IntegrationTests.java

示例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);
    }
}
 
开发者ID:imotSpot,项目名称:imotSpot,代码行数:11,代码来源:Configuration.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:11,代码来源:YAMLDemo.java

示例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());
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:13,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:9,代码来源:IntegrationTests.java

示例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());
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:12,代码来源:LoadTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:7,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:ziroby,项目名称:dmassist,代码行数:7,代码来源:EntityListImpl.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:18,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:18,代码来源:IntegrationTests.java

示例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);
}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:18,代码来源:IntegrationTests.java

示例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);

}
 
开发者ID:bibliocommons,项目名称:jyaml,代码行数:14,代码来源:IntegrationTests.java


注:本文中的org.ho.yaml.Yaml.dump方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。