-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
55 lines (40 loc) · 1.56 KB
/
Copy pathMain.java
File metadata and controls
55 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) {
HashTypeYaml yaml = new HashTypeYaml();
try {
HashTypeYaml.dump(new FileInputStream("test1.yml"));
System.out.println();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
Map<String, Object> map1 = yaml.decode(new FileInputStream("test1.yml"));
for (String key : map1.keySet()) {
System.out.println(key + ": " + map1.get(key));
}
System.out.println();
// For example, get `id`, `title` and `users`.
System.out.println(map1.get("test1/id")); // => 1234
System.out.println(map1.get("test1/data/title")); // => ABC Team
List users = (List) map1.get("test1/data/users");
System.out.println(users.get(1)); // => Bob
System.out.println();
} catch (IOException e) {
e.printStackTrace();
}
HashTypeYaml.dump("test2.yml");
System.out.println();
Map<String, Object> map2 = yaml.decodeOrEmpty("test2.yml");
// Get top level list.
System.out.println(map2.get(""));
System.out.println();
// Because not found test3.yml, `map3` goes empty.
Map<String, Object> map3 = yaml.decodeOrEmpty("test3.yml");
System.out.println("isEmpty: " + map3.isEmpty());
}
}