From a3bb8416324e33f0fb539610b3523a82671f1ce4 Mon Sep 17 00:00:00 2001 From: binsky Date: Mon, 14 Feb 2022 19:47:24 +0100 Subject: [PATCH] implement getting resource file as String --- src/main/java/ResourceApi.java | 5 +++++ src/test/java/ResourceApiTest.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/ResourceApi.java b/src/main/java/ResourceApi.java index 23cdcca..78cdbe1 100644 --- a/src/main/java/ResourceApi.java +++ b/src/main/java/ResourceApi.java @@ -5,6 +5,11 @@ import java.io.InputStreamReader; public class ResourceApi { + public String getFileFromResourceAsString(String fileName) throws IOException { + InputStream inputStream = getFileFromResourceAsStream(fileName); + return getStringFromInputStream(inputStream); + } + public InputStream getFileFromResourceAsStream(String fileName) { //ClassLoader classLoader = getClass().getClassLoader(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); diff --git a/src/test/java/ResourceApiTest.java b/src/test/java/ResourceApiTest.java index 3c985ab..b2ef993 100644 --- a/src/test/java/ResourceApiTest.java +++ b/src/test/java/ResourceApiTest.java @@ -40,4 +40,9 @@ class ResourceApiTest { InputStream is = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8)); assertEquals(resourceApi.getStringFromInputStream(is), testString); } + + @Test + void getFileFromResourceAsString() throws IOException { + assertTrue(resourceApi.getFileFromResourceAsString("german_wordlist.txt").contains("Alleinherrschaft")); + } }