-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathResourceUtils.java
More file actions
37 lines (29 loc) · 1.13 KB
/
ResourceUtils.java
File metadata and controls
37 lines (29 loc) · 1.13 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
package software.nhs.fhirvalidator.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResourceUtils {
static Logger log = LoggerFactory.getLogger(ResourceUtils.class);
private ResourceUtils() {
throw new IllegalStateException("Utility class");
}
public static String getResourceContent(String resource) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
ByteArrayOutputStream result;
try (InputStream inputStream = loader.getResourceAsStream(resource)) {
result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
for (int length; (length = inputStream.read(buffer)) != -1;) {
result.write(buffer, 0, length);
}
}
return result.toString("UTF-8");
} catch (IOException ex) {
log.error(ex.getMessage(), ex);
throw new RuntimeException("error in getResourceContent", ex);
}
}
}