Skip to content

Commit

Permalink
feat: getting a template from a URL (refs tomasbjerre#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
skrypetsviacheslav committed Jun 5, 2024
1 parent 9e70f33 commit 0ed0ff2
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 0ed0ff2

Please sign in to comment.