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使用的时候更为灵活 ...
随机推荐
- MySQL 二进制日志(Binary Log)
同大多数关系型数据库一样,日志文件是MySQL数据库的重要组成部分. MySQL有几种不同的日志文件.通常包括错误日志文件,二进制日志,通用日志,慢查询日志,等等.这些日志能够帮助我们定位mysqld ...
- hdu2795Billboard(线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=2795 单点更新,树存储的为某一行内剩余的长度 // File Name: hdu2795.cpp // Auth ...
- [Angular 2] Simple intro Http
To use http, we need to import the HTTP_PROVIDER, so that we can inject http to other component: imp ...
- ARM Cortex-M
振荡周期.时钟周期.机器周期.指令周期 一个机器周期包含12个振荡周期或6个时钟周期 指令的执行时间称作指令周期(单.双.四周期) (1)振荡周期 振荡周期指为单片机提供定时信号的振荡源的 ...
- IIS7的安装详解
IIS7安装流程规范 1, IIS常用的功能模块介绍: 1) 静态内容:可发布静态 Web 文件格式,比如 HTML 页面和图像文件. 2) 默认文档:允许您配置当 ...
- Ajax (jquery)实现智能提示搜索框(in Django)
搜索框输入搜索名字,从数据库中筛选名字, 如果有包含输入的字母的名字则以json格式返回并且显示在搜索框下: html文件: <!DOCTYPE html> <ht ...
- hadoop mapreduce 端参数优化
在MapReduce执行过程中,特别是Shuffle阶段,尽量使用内存缓冲区存储数据,减少磁盘溢写次数:同时在作业执行过程中增加并行度,都能够显著提高系统性能,这也是配置优化的一个重要依据. 下面分别 ...
- Servlet 技术全总结 (已完成,不定期增加内容)
Servlet是独立于平台和协议的服务器端的java应用程序,处理请求的信息并将其发送到客户端. Servlet的客户端可以提出请求并动态获得响应. Servlet动态生成web页面,担当浏览器或其他 ...
- uva 10260 - Soundex
题目:编码翻译,有些字母有对应的数字,有的没有,如果连续对应的数字相同只输出一个. #include <iostream> #include <cstdlib> #includ ...
- [转]Windows Shell 编程 第九章 【来源:http://blog.csdn.net/wangqiulin123456/article/details/7987969】
第九章 图标与Windows任务条 如果问一个非程序人员Windows最好的特色是什么,得到的答案应该是系统最有吸引力的图标.无论是Windows98现在支持的通用串行总线(USB)还是WDM(看上去 ...