/**
* 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 操作的更多相关文章

  1. 04 . kubernetes资源清单YAML入门

    YAML 通过k8s操作yaml配置文件在node上创建资源,yaml配置文件就像船垛,用来操控docker这艘大船 yam是专门用来写配置文件的语言,非常简洁和强大.而实际上使用yaml配置文件创建 ...

  2. Kubernetes实战指南(三十三):都0202了,你还在手写k8s的yaml文件?

    目录 1. k8s的yaml文件到底有多复杂 2. 基于图形化的方式自动生成yaml 2.1 k8s图形化管理工具Ratel安装 2.2 使用Ratel创建生成yaml文件 2.2.1 基本配置 2. ...

  3. Homestead 使用总结

    homestead Laravel Homestead是一个官方预封装的Vagrant"箱子" 内置 Nginx.PHP 5.6.MySQL.Postgres.Redis.Memc ...

  4. 个人开源项目testall 持续更新中···

    项目在GitHub上:https://github.com/x113773/testall ,喜欢的给个星星呀,亲~ 打算把用到过的和学习过的,所有前后端技术都集成到这个项目里,并在issues里配以 ...

  5. Keras 学习之旅(一)

    软件环境(Windows): Visual Studio Anaconda CUDA MinGW-w64 conda install -c anaconda mingw libpython CNTK ...

  6. 腾讯基于Kubernetes的企业级容器云平台GaiaStack (转)

    GaiaStack介绍 GaiaStack是腾讯基于Kubernetes打造的容器私有云平台.这里有几个关键词: 腾讯:GaiaStack可服务腾讯内部所有BG的业务: Kubernetes:Gaia ...

  7. YAML-CPP

    yaml作为一种便捷的文件格式,通过c++进行操作时,可以利用yaml-cpp进行. 一,yaml-cpp的安装 下载源码 git clone https://github.com/jbeder/ya ...

  8. Python Selenium Cookie 绕过验证码实现登录

    Python Selenium Cookie 绕过验证码实现登录 之前介绍过博客园的通过cookie 绕过验证码实现登录的方法.这里并不多余,会增加分析和另外一种方法实现登录. 1.思路介绍 1.1. ...

  9. kubectl技巧之通过jsonpath截取属性

    系列目录 前面一节我们介绍了使用go-template截取属性,go-template功能非常强大,可以定义变量,使用流程控制等,这是jsonpath所不具备的.然而,jsonpth使用的时候更为灵活 ...

随机推荐

  1. Color 颜色码-英文名称-十六进制-RGB对照表

      色 英文代码 形像颜色 HEX格式 RGB格式 LightPink 浅粉红 #FFB6C1 255,182,193 Pink 粉红 #FFC0CB 255,192,203 Crimson 猩红 # ...

  2. C++ lambda 表达式传递的变量默认不可变

    我遇到例如以下问题: int count=0; listener->onTouchMoved=[count](Touch* t,Event* e){ count++; log("onT ...

  3. BNU10804:域名统计

    域名(Domain Name),是由一串用点分隔的名字组成的Internet上某一台计算机或计算机组的名称,用于在数据传输时标识计算机的电子方位(有时也指地理位置),目前域名已经成为 互联网的品牌.网 ...

  4. (1)QlikView概要

    本文的内容,以学习的两个合伙人: I.什么是Qlikview II. QlikView 的优点和缺点 1.1什么是QlikView 1.1什么是QlikView QlikView是一个工具,一个商业智 ...

  5. samba服务日志文件-密码文件及启停

    1.Samba服务日志文件日志文件对于samba非常重要,它存储着客户端访问samba服务器的信息,以及samba服务的错误提示信息等,可以通过分析日志,帮助解决客户端访问和服务器维护等问题.在/et ...

  6. css布局&初始化&基准样式

    学习css布局比较好的网站 学习css布局 1.css设置模块 typography(字体) colour(颜色) link(链接) forms(表单) layout(布局) navigation(导 ...

  7. 127.0.0.1与localhost与ip的区别

    127.0.0.1与localhost与ip的区别 May 18, 2014 localhost 不联网不使用网卡,不受防火墙和网卡限制本机访问 一般使用 本地套接字文件AF_UNIX 应用程序一般约 ...

  8. [转]Mac App distribution in App Store

    Mac程序的大包上传和iOS的有些许不同,因为Mac app既可以上传到store,也可以不通过store供人下载.因此,code sign和provision要根据情况(开发,release< ...

  9. [置顶] chinayaosir近10年来所阅读的世界著名IT书籍-图文并茂

    1.人生观(包括做人原则,心理学,投资,销售) 一个人从来到世上,很多东西都是空白, 阅读一些正能量的书籍,把里面的理论用于生活,不断的应用它, 这些观念就会如同软件一样,不断的升级你的大脑, 合理的 ...

  10. 转载:spring ,struct2 在 web.xml中的配置

    转载网址:http://blog.sina.com.cn/s/blog_4c6e822d0102dv63.html <!-- Struts2 need begin-->  <filt ...