From 0ed0ff277acf41074403bde20e2d53d81ed7df16 Mon Sep 17 00:00:00 2001 From: Viacheslav Skrypets Date: Wed, 5 Jun 2024 16:23:28 +0300 Subject: [PATCH] feat: getting a template from a URL (refs #184) --- .../internal/util/ResourceLoader.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/se/bjurr/gitchangelog/internal/util/ResourceLoader.java b/src/main/java/se/bjurr/gitchangelog/internal/util/ResourceLoader.java index 0463834..19b4d2c 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/util/ResourceLoader.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/util/ResourceLoader.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URL; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; @@ -30,6 +31,9 @@ public static String getResourceOrFile(final String resourceName, final Charset getResourceFromClassLoader( resourceName, Thread.currentThread().getContextClassLoader()); } + if (inputStream == null) { + inputStream = getResourceFromURL(resourceName); + } if (inputStream == null) { throw new FileNotFoundException( @@ -61,4 +65,13 @@ private static InputStream getResourceFromClassLoader( } return inputStream; } -} + + private static InputStream getResourceFromURL(final String resourceName) { + try { + URL url = new URL(resourceName); + return url.openStream(); + } catch (IOException e) { + return null; + } + } +} \ No newline at end of file