Skip to content

Commit 036b36d

Browse files
committed
added TestUtils.openInputStream
1 parent 05cebe9 commit 036b36d

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

tests/objectbox-java-test/src/main/java/io/objectbox/TestUtils.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
package io.objectbox;
1818

19+
import org.greenrobot.essentials.io.IoUtils;
20+
1921
import java.io.ByteArrayInputStream;
2022
import java.io.ByteArrayOutputStream;
2123
import java.io.File;
24+
import java.io.FileInputStream;
25+
import java.io.FileNotFoundException;
2226
import java.io.IOException;
2327
import java.io.InputStream;
2428
import java.io.InputStreamReader;
@@ -27,31 +31,29 @@
2731
import java.io.Reader;
2832
import java.io.Serializable;
2933

30-
import org.greenrobot.essentials.io.FileUtils;
31-
import org.greenrobot.essentials.io.IoUtils;
32-
3334
public class TestUtils {
3435

3536
public static String loadFile(String filename) {
36-
String json;
37-
InputStream in = TestUtils.class.getResourceAsStream("/" + filename);
3837
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);
5141
} catch (IOException e) {
5242
throw new RuntimeException(e);
5343
}
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;
5557
}
5658

5759
public static <T extends Serializable> T serializeDeserialize(T entity) throws IOException, ClassNotFoundException {

0 commit comments

Comments
 (0)