1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml;
17
18 import java.io.BufferedInputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 public class Util {
23
24 public static String getLocalResource(String theName) {
25 try {
26 InputStream input;
27 input = YamlDocument.class.getClassLoader().getResourceAsStream(theName);
28 if (input == null) {
29 throw new RuntimeException("Can not find " + theName);
30 }
31 BufferedInputStream is = new BufferedInputStream(input);
32 StringBuilder buf = new StringBuilder(3000);
33 int i;
34 try {
35 while ((i = is.read()) != -1) {
36 buf.append((char) i);
37 }
38 } finally {
39 is.close();
40 }
41 String resource = buf.toString();
42
43 String[] lines = resource.split("\\r?\\n");
44 StringBuilder buffer = new StringBuilder();
45 for (int j = 0; j < lines.length; j++) {
46 buffer.append(lines[j]);
47 buffer.append("\n");
48 }
49 return buffer.toString();
50 } catch (IOException e) {
51 throw new RuntimeException(e);
52 }
53 }
54 }