From f89dd09539c792a230a1adb9f30837da1c591034 Mon Sep 17 00:00:00 2001 From: Ephrim Stanley Date: Tue, 27 Jun 2023 00:48:28 -0400 Subject: [PATCH] WIP --- .../backend/simple/canned/StaticEntities.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/legend-sdlc-server-demo/src/main/java/org/finos/legend/sdlc/server/backend/simple/canned/StaticEntities.java b/legend-sdlc-server-demo/src/main/java/org/finos/legend/sdlc/server/backend/simple/canned/StaticEntities.java index 7977ea756d..16a343bf19 100644 --- a/legend-sdlc-server-demo/src/main/java/org/finos/legend/sdlc/server/backend/simple/canned/StaticEntities.java +++ b/legend-sdlc-server-demo/src/main/java/org/finos/legend/sdlc/server/backend/simple/canned/StaticEntities.java @@ -22,20 +22,32 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.server.backend.simple.domain.model.entity.SimpleBackendEntity; -import java.net.URL; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.List; +import java.util.stream.Collectors; public class StaticEntities { public static String load(String resourceName) throws Exception { - String fullName = "/backend/simple/canned/" + resourceName; - URL resource = StaticEntities.class.getResource(fullName); - byte[] bytes = Files.readAllBytes(Paths.get(resource.toURI())); - return new String(bytes, Charset.defaultCharset()); + InputStream resourceAsStream = null; + try + { + String fullName = "/backend/simple/canned/" + resourceName; + resourceAsStream = StaticEntities.class.getResourceAsStream(fullName); + BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream)); + String contents = reader.lines().collect(Collectors.joining(System.lineSeparator())); + return contents; + } + finally + { + if (resourceAsStream != null) + { + resourceAsStream.close(); + } + } } public static MutableMap loadEntities(String resourceName) throws Exception