YAML 1.6 Operations

Source: Internet
Author: User

/*** Copyright (c),http://www.snakeyaml.org* * Licensed under the Apache License, Version 2.0 (the "License"); * you are not a use this file except in compliance With the License. * Obtain a copy of the License at * *http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable or agreed to writing, software * Distributed under the License is distribute D on ' 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. */ Packageexamples;ImportJava.io.ByteArrayInputStream;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.IOException;ImportJava.io.InputStream;Importjava.util.List;ImportJava.util.Map;Importjunit.framework.TestCase;ImportOrg.yaml.snakeyaml.Yaml; Public classLoadexampletestextendsTestCase {@SuppressWarnings ("Unchecked")     Public voidtestLoad () {Yaml Yaml=NewYaml (); 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 voidtestloadfromstring () {Yaml Yaml=NewYaml (); String Document= "Hello:25"; @SuppressWarnings ("Unchecked") Map<string, integer> map = (map<string, integer>) Yaml.load (document); Assertequals ("{hello=25}", map.tostring ()); Assertequals (NewInteger, Map.get ("Hello")); }     Public voidTestloadfromstream ()throwsIOException {inputstream input=NewFileInputStream (NewFile ("Src/test/resources/reader/utf-8.txt")); Yaml Yaml=NewYaml (); Object Data=yaml.load (input); Assertequals ("Test", data); //data = Yaml.load (NewBytearrayinputstream ("Test2". GetBytes ("UTF-8")))); Assertequals ("Test2", data);    Input.close (); }     Public voidTestloadmanydocuments ()throwsIOException {inputstream input=NewFileInputStream (NewFile ("Src/test/resources/specification/example2_28.yaml")); Yaml Yaml=NewYaml (); intCounter = 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 Operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.