-
Notifications
You must be signed in to change notification settings - Fork 1
/
ResourceReader.java
25 lines (21 loc) · 1.07 KB
/
ResourceReader.java
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
package com.exasol.projectkeeper.validators.files;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import com.exasol.errorreporting.ExaError;
class ResourceReader {
String readFromResource(final String resourceName) {
final String templateContent = readResource(resourceName);
return templateContent.replace("\r", "").replace("\n", System.lineSeparator());
}
private String readResource(final String resourceName) {
try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(resourceName)) {
return new String(Objects.requireNonNull(resourceAsStream).readAllBytes(), StandardCharsets.UTF_8);
} catch (final IOException | NullPointerException exception) {
throw new IllegalStateException(ExaError.messageBuilder("F-PK-CORE-57")
.message("Failed to read template from resource {{resource name}}.", resourceName)
.ticketMitigation().toString(), exception);
}
}
}