/*** 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