commit 4ac54038b2b79c3a8a922e44134b0ceb877aea68
parent 246f657572793aa5a43097b4c1b880772f4823d8
Author: WimDupont <WimDupont@users.noreply.gitlab.com>
Date: Sat, 6 Nov 2021 21:16:11 +0100
fix reading releasenotes as jar
Diffstat:
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/sxcy/sxcybot/util/ReleaseNotesUtil.java b/src/main/java/com/sxcy/sxcybot/util/ReleaseNotesUtil.java
@@ -11,11 +11,10 @@ import org.springframework.stereotype.Component;
import java.awt.Color;
import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
+import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -51,13 +50,13 @@ public class ReleaseNotesUtil {
private static Map<String, String> getReleaseNotes() {
Map<String, String> releaseNotes = new LinkedHashMap<>();
try {
- URL file = Optional.ofNullable(ReleaseNotesUtil.class.getResource("/releasenotes.csv"))
+ InputStream in = Optional.ofNullable(ReleaseNotesUtil.class.getResourceAsStream("/releasenotes.csv"))
.orElseThrow(() -> new IOException("File releasenotes.csv not found!"));
- Files.lines(Paths.get(file.toURI())).forEach(line -> {
+ Arrays.stream(new String(in.readAllBytes(), StandardCharsets.UTF_8).split("\n")).forEach(line -> {
if (!line.isEmpty())
releaseNotes.put(line.split(";")[0], line.split(";")[1].trim());
});
- } catch (URISyntaxException | IOException e) {
+ } catch (IOException e) {
log.error(e.getMessage(), e);
}
return releaseNotes;