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使用的时候更为灵活 ...
随机推荐
- FilterDispatcher 的作用(struts2.1.3以前,新版本改了)
org.apache.struts2.dispatcher.FilterDispatcher是Struts2的主要的Filter,负责四个方面的功能: (1)执行Actions (2)清除Action ...
- Eclipse 4.2 + Tomcat 7.x + JDK 7 搭建Java Web开发环境
1. 准备工具 Eclipse 4.2 (到官网下载:http://www.eclipse.org/downloads/ 要下载Eclipse IDE for Java EE Developers ...
- C#调用R语言输出图片
参考:http://rdotnet.codeplex.com/documentation REngine.SetEnvironmentVariables(); REngine engine = R ...
- Flex中的折线图
1.问题背景 在Flex中,制作一个折线图.而且给折线图的横轴和纵轴进行样式设置,详细实现过程例如以下: 2.实现实例 (1)设置横轴样式和数据绑定 <mx:horizontalAxis> ...
- Ignatius and the Princess III --undo
Ignatius and the Princess III Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (J ...
- hdu4893Wow! Such Sequence! (线段树)
Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger f ...
- LDAP缓存命令
启动cacao及实例: [root@rusky bin]# cd /home/ldap/iamldap/dsee6/cacao_2/cacao/bin [root@rusky bin]# ./caca ...
- HTML基础总结<文本格式>
HTML 文本格式化标签 标签 描述 <b> 定义粗体文本 <em> 呈现为被强调的文本 <i> 定义斜体字 <small> 定义小号字 <str ...
- HTML5 Canvas图片操作简单实例1
1.加载显示图片 <canvas id="canvasOne" class="myCanvas" width="500" height ...
- WPF 获取屏幕分辨率(获取最大宽高)等
double x = SystemParameters.WorkArea.Width;//得到屏幕工作区域宽度 double y = SystemParameters.WorkArea.Height; ...