Skip to content

Commit

Permalink
Ensure class resource stream is closed in ResourceUtils
Browse files Browse the repository at this point in the history
This ensures that `ResourceUtils.loadResource` closes the resource stream when reading all bytes.
  • Loading branch information
dakrone committed Nov 7, 2024
1 parent 897573a commit 42c4bcc
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ static byte[] loadVersionedResourceUTF8(
}

public static String loadResource(Class<?> clazz, String name) throws IOException {
InputStream is = clazz.getResourceAsStream(name);
if (is == null) {
throw new IOException("Resource [" + name + "] not found in classpath.");
try (InputStream is = clazz.getResourceAsStream(name)) {
if (is == null) {
throw new IOException("Resource [" + name + "] not found in classpath.");
}
return new String(is.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
}
return new String(is.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
}

}

0 comments on commit 42c4bcc

Please sign in to comment.