本文整理汇总了Java中org.ho.yaml.Yaml类的典型用法代码示例。如果您正苦于以下问题:Java Yaml类的具体用法?Java Yaml怎么用?Java Yaml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Yaml类属于org.ho.yaml包,在下文中一共展示了Yaml类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: readSingleSchedulerConfig
import org.ho.yaml.Yaml; //导入依赖的package包/类
public static Map<String, Object> readSingleSchedulerConfig(String filePath) {
Map<String, Object> res = new HashMap<String, Object>();
File file = new File(filePath);
try {
Map<String, Object> map = Yaml.loadType(file, HashMap.class);
for(Map.Entry<String, Object> entry : map.entrySet()) {
if(entry.getValue() instanceof Map)
continue;
res.put(entry.getKey(), entry.getValue());
}
} catch(FileNotFoundException fe) {
fe.printStackTrace();
}
return res;
}
开发者ID:knshen,项目名称:JSearcher,代码行数:18,代码来源:YamlHandler.java
示例3: testWebSiteExample2
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testWebSiteExample2() throws Exception{
String yamlText =
"--- \n" +
"date: 11/29/2005\n" +
"receipts:\n" +
" - store: ken stanton music\n" +
" category: entertainment\n" +
" description: saxophone repair\n" +
" total: 382.00\n" +
" - store: walmart\n" +
" category: groceries\n" +
" total: 14.26";
Entry entry = Yaml.loadType(yamlText, Entry.class);
assertEquals("11/29/2005", entry.getDate());
assertEquals(2, entry.getReceipts().length);
assertEquals("ken stanton music", entry.getReceipts()[0].getStore());
assertEquals("groceries", entry.getReceipts()[1].getCategory());
assertEquals(382.00, entry.getReceipts()[0].getTotal());
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:21,代码来源:IntegrationTests.java
示例4: testWebSiteExample2WithRealDate
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testWebSiteExample2WithRealDate() throws Exception{
String yamlText =
"--- \n" +
"date: 11/29/2005\n" +
"receipts:\n" +
" - store: ken stanton music\n" +
" category: entertainment\n" +
" description: saxophone repair\n" +
" total: 382.00\n" +
" - store: walmart\n" +
" category: groceries\n" +
" total: 14.26";
Entry2 entry = Yaml.loadType(yamlText, Entry2.class);
assertEquals(new Date("11/29/2005"), entry.getDate());
assertEquals(2, entry.getReceipts().length);
assertEquals("ken stanton music", entry.getReceipts()[0].getStore());
assertEquals("groceries", entry.getReceipts()[1].getCategory());
assertEquals(382.00, entry.getReceipts()[0].getTotal());
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:21,代码来源:IntegrationTests.java
示例5: testSkimoInlinedList
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSkimoInlinedList(){
String yamlText =
"---\n" +
"arrays:\n" +
" - &1\n" +
" dims:\n" +
" - 10\n" +
" id: 1610612737\n" +
" name: a\n" +
"cacheline: -1\n" +
"context:\n" +
" constraints:\n" +
" -\n" +
" - [1, 1, 0]\n" +
" - [1, -1, 2]\n" +
" dim: 0\n" +
" params:\n" +
" - &2\n" +
" name: n\n";
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals("-1", pdg.cacheline);
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:23,代码来源:IntegrationTests.java
示例6: testSkimoIgnoreTransfers
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSkimoIgnoreTransfers(){
String yamlText =
"--- !perl/PDG\n" +
"arrays:\n" +
" - &1\n" +
" dims:\n" +
" - 10\n" +
" id: 1610612737\n" +
" name: a\n" +
"cacheline: -1\n" +
"context: !perl/PDG::UnionSet\n" +
" constraints:\n" +
" - !perl/PDL::Matrix\n" +
" - [1, 1, 0]\n" +
" - [1, -1, 2]\n" +
" dim: 0\n" +
" params:\n" +
" - &2\n" +
" name: n\n";
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals("-1", pdg.cacheline);
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:23,代码来源:IntegrationTests.java
示例7: testSkimoArray
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSkimoArray(){
String yamlText =
"---\n" +
"context:\n" +
" constraints:\n" +
" -\n" +
" - [1, 1, 0]\n" +
" - [1, -1, 2]\n" +
" dim: 0";
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals(pdg.context.dim, 0);
assertEquals(pdg.context.constraints[0][0][0], 1);
assertEquals(pdg.context.constraints[0][0][1], 1);
assertEquals(pdg.context.constraints[0][0][2], 0);
assertEquals(pdg.context.constraints[0][1][0], 1);
assertEquals(pdg.context.constraints[0][1][1], -1);
assertEquals(pdg.context.constraints[0][1][2], 2);
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:19,代码来源:IntegrationTests.java
示例8: testAnchorIgnored
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testAnchorIgnored(){
String yamlText =
"---\n" +
"ignored:\n" +
" - &1\n" +
" dims: []\n" +
" id: 1610612737\n" +
" name: a\n" +
"arrays:\n" +
" - *1";
try {
PDG pdg = Yaml.loadType(yamlText, PDG.class);
assertEquals(pdg.arrays[0].name, "a");
throw new Error("This should have failed.");
} catch (YamlException e) {
}
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:19,代码来源:IntegrationTests.java
示例9: 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
示例10: 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
示例11: testSequenceMapBug2
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testSequenceMapBug2(){
String s = "players:\n"+
" -\n"+
" name: Mark McGwire\n"+
" hr: 65\n"+
" avg: 0.278\n"+
" -\n"+
" name: Sammy Sosa\n"+
" hr: 63\n"+
" avg: 0.288\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"));
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:20,代码来源:IntegrationTests.java
示例12: 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
示例13: testOrdering
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testOrdering(){
Person p = new Person();
p.setName("kevin");
p.setAge(4);
p.setSalary(34859.0);
p.setNetWorth(new BigDecimal("1000000.00"));
System.out.println(Yaml.dump(p, true));
String expected =
"--- \r\n" +
"age: 4\r\n" +
"name: kevin\r\n" +
"netWorth: 1000000.00\r\n" +
"salary: 34859.0\r\n";
assertEquals(expected, Yaml.dump(p, true));
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:17,代码来源:IntegrationTests.java
示例14: testCanonicalGraph
import org.ho.yaml.Yaml; //导入依赖的package包/类
public void testCanonicalGraph(){
Person p = new Person();
p.setName("Bill");
Person spouse = new Person();
spouse.setName("Hillary");
p.setSpouse(spouse);
spouse.setSpouse(p);
List l = new ArrayList();
l.add(p);
l.add(spouse);
System.out.println(Yaml.dump(l));
String expected = "--- \r\n" +
"- &1 !org.ho.yaml.tests.Person\r\n" +
" name: Bill\r\n" +
" spouse: &2 !org.ho.yaml.tests.Person\r\n" +
" name: Hillary\r\n" +
" spouse: *1\r\n" +
"- *2\r\n";
assertEquals(expected, Yaml.dump(l));
}
开发者ID:bibliocommons,项目名称:jyaml,代码行数:21,代码来源:IntegrationTests.java
示例15: 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();
}
}
开发者ID:lichee,项目名称:JBrick,代码行数:28,代码来源:App.java
示例16: loadYamlToHashMap
import org.ho.yaml.Yaml; //导入依赖的package包/类
private static HashMap loadYamlToHashMap(String filePath) {
HashMap hashmap = null;
File f = new File(filePath);
try {
hashmap = Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return hashmap;
}
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:11,代码来源:TomcatConfigReadin.java
示例17: loadFileToHashMap
import org.ho.yaml.Yaml; //导入依赖的package包/类
public HashMap loadFileToHashMap(String filePath) {
HashMap hashmap = null;
File f = new File(filePath);
try {
hashmap = Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return hashmap;
}
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:11,代码来源:HadoopConfigReadin.java
示例18: 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");
}
}
开发者ID:redBorder,项目名称:rb-bi,代码行数:36,代码来源:ConfigFile.java
示例19: 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
示例20: getStorageConfig
import org.ho.yaml.Yaml; //导入依赖的package包/类
public static Map<String, Object> getStorageConfig(String filePath) {
Map<String, Object> res = new HashMap<String, Object>();
File file = new File(filePath);
try {
Map<String, Object> map = Yaml.loadType(file, HashMap.class);
for(Map.Entry<String, Object> entry : map.entrySet()) {
if(entry.getValue() instanceof Map && !entry.getKey().equals("cluster")) {
Map<String, Object> paras = (HashMap<String, Object>)entry.getValue();
res.put("host", paras.get("host"));
res.put("port", paras.get("port"));
if(entry.getKey().equals("mysql")) {
res.put("db", paras.get("db"));
res.put("user", paras.get("user"));
res.put("password", paras.get("password"));
}
else if(entry.getKey().equals("mongodb")) {
res.put("db", paras.get("db"));
}
else if(entry.getKey().equals("es")) {
res.put("cluster_name", paras.get("cluster_name"));
}
}
}
} catch(FileNotFoundException fe) {
fe.printStackTrace();
}
return res;
}
开发者ID:knshen,项目名称:JSearcher,代码行数:31,代码来源:YamlHandler.java
注:本文中的org.ho.yaml.Yaml类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论