From bda381a05d9970c8efa2550dfeaaa04a9d278292 Mon Sep 17 00:00:00 2001 From: Simon Hartley Date: Sat, 30 Sep 2023 00:00:02 +0100 Subject: [PATCH] Close InputStream after use --- src/main/java/com/resend/util/FileUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/resend/util/FileUtils.java b/src/main/java/com/resend/util/FileUtils.java index a4aa24b..25d54fd 100644 --- a/src/main/java/com/resend/util/FileUtils.java +++ b/src/main/java/com/resend/util/FileUtils.java @@ -12,10 +12,11 @@ public static String encodeFileToBase64(String filename) throws IOException { private static byte[] loadResourceFile(String filename) throws IOException { ClassLoader classLoader = FileUtils.class.getClassLoader(); - InputStream inputStream = classLoader.getResourceAsStream(filename); - if (inputStream == null) { - throw new IOException("Resource not found: " + filename); + try (InputStream inputStream = classLoader.getResourceAsStream(filename)) { + if (inputStream == null) { + throw new IOException("Resource not found: " + filename); + } + return inputStream.readAllBytes(); } - return inputStream.readAllBytes(); } -} \ No newline at end of file +}