Skip to content

Commit

Permalink
Correct way of finding Resource
Browse files Browse the repository at this point in the history
Fixes #63
  • Loading branch information
axel1200 authored and Brutus5000 committed Nov 5, 2018
1 parent a93ff05 commit 70752fd
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -171,8 +171,9 @@ private void getDefaultChoices(int questionID, int count) {
private String generateMapDescriptionHTML(MapVersion mapVersion) {
String formattedHtml;
try {
URL resource = getClass().getClassLoader().getResource("media/map_description_template.html");
String htmlTemplate = new String(Files.readAllBytes(Paths.get(resource.toURI())));
InputStream resourceAsStream = getClass().getResourceAsStream("/media/map_description_template.html");
BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream));
String htmlTemplate = reader.lines().collect(Collectors.joining("\n"));

formattedHtml = htmlTemplate.replaceAll("\\{map-player-count}", String.valueOf(mapVersion.getMaxPlayers()));
formattedHtml = formattedHtml.replaceAll("\\{preview-source}", mapVersion.getThumbnailUrlLarge().toString());
Expand Down

0 comments on commit 70752fd

Please sign in to comment.