|
16 | 16 |
|
17 | 17 | package io.objectbox; |
18 | 18 |
|
| 19 | +import org.greenrobot.essentials.io.IoUtils; |
| 20 | + |
19 | 21 | import java.io.ByteArrayInputStream; |
20 | 22 | import java.io.ByteArrayOutputStream; |
21 | 23 | import java.io.File; |
| 24 | +import java.io.FileInputStream; |
| 25 | +import java.io.FileNotFoundException; |
22 | 26 | import java.io.IOException; |
23 | 27 | import java.io.InputStream; |
24 | 28 | import java.io.InputStreamReader; |
|
27 | 31 | import java.io.Reader; |
28 | 32 | import java.io.Serializable; |
29 | 33 |
|
30 | | -import org.greenrobot.essentials.io.FileUtils; |
31 | | -import org.greenrobot.essentials.io.IoUtils; |
32 | | - |
33 | 34 | public class TestUtils { |
34 | 35 |
|
35 | 36 | public static String loadFile(String filename) { |
36 | | - String json; |
37 | | - InputStream in = TestUtils.class.getResourceAsStream("/" + filename); |
38 | 37 | try { |
39 | | - if (in != null) { |
40 | | - Reader reader = new InputStreamReader(in, "UTF-8"); |
41 | | - json = IoUtils.readAllCharsAndClose(reader); |
42 | | - |
43 | | - } else { |
44 | | - String pathname = "src/main/resources/" + filename; |
45 | | - File file = new File(pathname); |
46 | | - if (!file.exists()) { |
47 | | - file = new File("lib-test-java/" + pathname); |
48 | | - } |
49 | | - json = FileUtils.readUtf8(file); |
50 | | - } |
| 38 | + InputStream in = openInputStream("/" + filename); |
| 39 | + Reader reader = new InputStreamReader(in, "UTF-8"); |
| 40 | + return IoUtils.readAllCharsAndClose(reader); |
51 | 41 | } catch (IOException e) { |
52 | 42 | throw new RuntimeException(e); |
53 | 43 | } |
54 | | - return json; |
| 44 | + } |
| 45 | + |
| 46 | + public static InputStream openInputStream(String filename) throws FileNotFoundException { |
| 47 | + InputStream in = TestUtils.class.getResourceAsStream("/" + filename); |
| 48 | + if (in == null) { |
| 49 | + String pathname = "src/main/resources/" + filename; |
| 50 | + File file = new File(pathname); |
| 51 | + if (!file.exists()) { |
| 52 | + file = new File("lib-test-java/" + pathname); |
| 53 | + } |
| 54 | + in = new FileInputStream(file); |
| 55 | + } |
| 56 | + return in; |
55 | 57 | } |
56 | 58 |
|
57 | 59 | public static <T extends Serializable> T serializeDeserialize(T entity) throws IOException, ClassNotFoundException { |
|
0 commit comments