GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — added TestUtils.openInputStream · Night-Kang/objectbox-java@036b36d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/objectbox-java-test/src/main/java/io/objectbox
    • TestUtils.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/main/java/io/objectbox/TestUtils.java
+20-18Lines 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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.