yaml 1.6 操作
/**
* Copyright (c) 2008, http://www.snakeyaml.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package examples; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map; import junit.framework.TestCase; import org.yaml.snakeyaml.Yaml; public class LoadExampleTest extends TestCase {
@SuppressWarnings("unchecked")
public void testLoad() {
Yaml yaml = new Yaml();
String document = "\n- Hesperiidae\n- Papilionidae\n- Apatelodidae\n- Epiplemidae";
List<String> list = (List<String>) yaml.load(document);
assertEquals("[Hesperiidae, Papilionidae, Apatelodidae, Epiplemidae]", list.toString());
} public void testLoadFromString() {
Yaml yaml = new Yaml();
String document = "hello: 25";
@SuppressWarnings("unchecked")
Map<String, Integer> map = (Map<String, Integer>) yaml.load(document);
assertEquals("{hello=25}", map.toString());
assertEquals(new Integer(25), map.get("hello"));
} public void testLoadFromStream() throws IOException {
InputStream input = new FileInputStream(new File("src/test/resources/reader/utf-8.txt"));
Yaml yaml = new Yaml();
Object data = yaml.load(input);
assertEquals("test", data);
//
data = yaml.load(new ByteArrayInputStream("test2".getBytes("UTF-8")));
assertEquals("test2", data);
input.close();
} public void testLoadManyDocuments() throws IOException {
InputStream input = new FileInputStream(new File(
"src/test/resources/specification/example2_28.yaml"));
Yaml yaml = new Yaml();
int counter = 0;
for (Object data : yaml.loadAll(input)) {
assertNotNull(data);
assertTrue(data.toString().length() > 1);
counter++;
}
assertEquals(3, counter);
input.close();
}
} https://bitbucket.org/asomov/snakeyaml/wiki/Documentation#markdown-header-dumping-a-custom-yaml-document https://bitbucket.org/asomov/snakeyaml/src/tip/src/test/java/examples/LoadExampleTest.java?fileviewer=file-view-default
yaml 1.6 操作的更多相关文章
- 04 . kubernetes资源清单YAML入门
YAML 通过k8s操作yaml配置文件在node上创建资源,yaml配置文件就像船垛,用来操控docker这艘大船 yam是专门用来写配置文件的语言,非常简洁和强大.而实际上使用yaml配置文件创建 ...
- Kubernetes实战指南(三十三):都0202了,你还在手写k8s的yaml文件?
目录 1. k8s的yaml文件到底有多复杂 2. 基于图形化的方式自动生成yaml 2.1 k8s图形化管理工具Ratel安装 2.2 使用Ratel创建生成yaml文件 2.2.1 基本配置 2. ...
- Homestead 使用总结
homestead Laravel Homestead是一个官方预封装的Vagrant"箱子" 内置 Nginx.PHP 5.6.MySQL.Postgres.Redis.Memc ...
- 个人开源项目testall 持续更新中···
项目在GitHub上:https://github.com/x113773/testall ,喜欢的给个星星呀,亲~ 打算把用到过的和学习过的,所有前后端技术都集成到这个项目里,并在issues里配以 ...
- Keras 学习之旅(一)
软件环境(Windows): Visual Studio Anaconda CUDA MinGW-w64 conda install -c anaconda mingw libpython CNTK ...
- 腾讯基于Kubernetes的企业级容器云平台GaiaStack (转)
GaiaStack介绍 GaiaStack是腾讯基于Kubernetes打造的容器私有云平台.这里有几个关键词: 腾讯:GaiaStack可服务腾讯内部所有BG的业务: Kubernetes:Gaia ...
- YAML-CPP
yaml作为一种便捷的文件格式,通过c++进行操作时,可以利用yaml-cpp进行. 一,yaml-cpp的安装 下载源码 git clone https://github.com/jbeder/ya ...
- Python Selenium Cookie 绕过验证码实现登录
Python Selenium Cookie 绕过验证码实现登录 之前介绍过博客园的通过cookie 绕过验证码实现登录的方法.这里并不多余,会增加分析和另外一种方法实现登录. 1.思路介绍 1.1. ...
- kubectl技巧之通过jsonpath截取属性
系列目录 前面一节我们介绍了使用go-template截取属性,go-template功能非常强大,可以定义变量,使用流程控制等,这是jsonpath所不具备的.然而,jsonpth使用的时候更为灵活 ...
随机推荐
- psp个人软件过程需求文档
1. 业务需求 1.1 应用背景 开发软件项目进度计划总是那么不准确,延期经常出现,跟可恨的是甚至无法给出一个相对比较明确的延迟时间.很大 因素在于分配给开发人员的完成时间与开发人员的实际完成时间有 ...
- [RxJS] Observables can complete
The Observer object has the functions next() and error(). In this lesson we will see the other (and ...
- Creating Apps With Material Design —— Defining Shadows and Clipping Views
View转载请注明 http://blog.csdn.net/eclipsexys 翻译自Developer Android,时间仓促,有翻译问题请留言指出,谢谢 定义阴影和裁减 材料设计引入了深度的 ...
- POJ 1386 有向图欧拉通路
题意:给你一些字符串,这些字符串可以首位相接(末位置如果和另一个字符串的首位置相同的话就可以相连) .然后问你是否可以全部连起来. 思路:就是取出每个字符串的首尾位置,然后求出出度和入度,根据有向欧拉 ...
- 完全卸载sql2005
转自:http://www.cnblogs.com/mytechblog/articles/1883961.html 1.Stop 所有服务 2.在控制面板中卸载所有与SQL Server 2005相 ...
- NS2仿真:使用NS仿真软件模拟简单网络模型
NS2仿真实验报告1 实验名称:使用NS仿真软件模拟简单网络模型 实验日期:2015年3月2日~2015年3月7日 实验报告日期:2015年3月8日 一.实验环境(网络平台,操作系统,网络拓扑图) 运 ...
- 配置Samba服务
1. samba服务用在什么地方?samba服务用于把Linux服务器上的文件或者打印接共享给windows或者Linux.2. 在samba服务的配置文件中,[global]配置部分的securit ...
- css3选择符使用个人理解。
元素选择符: 通配选择符:一般用* 星号表示 他会命中整体标签. 类型选择符:一般用者空格表示 他会命中标签自己的所有子元素. ID选择符: 一般用# 井号表示 他会命中以id为属性的标签 ...
- easyui datagrid 行数
$('#gridList').datagrid('getData').rows.length
- 深入理解REST与Servlet架构的区别
本身这个比较是个伪命题,因为 RESTful Service是一个软件架构“风格”, 而servlet是java 服务端的一种技术 之所以把它们拿出来比较,是由于它们代表了两个时代的技术风格与架构.下 ...