Skip to content

Commit

Permalink
fix: resources stream close error
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinten10 committed Oct 25, 2022
1 parent 396c060 commit 3b7b811
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ final class JavaFileLoader {
*/
static InputStreamReader loadJavaResources(String fileName) throws NullPointerException, IllegalArgumentException {
Objects.requireNonNull(fileName, "fileName not found.");
try (InputStream in = JavaFileLoader.class.getResourceAsStream(fileName)) {
return new InputStreamReader(in, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new IllegalArgumentException(fileName + " file not found.", e);
}
InputStream in = JavaFileLoader.class.getResourceAsStream(fileName);
return new InputStreamReader(in, StandardCharsets.UTF_8);
}

/**
Expand All @@ -42,9 +39,8 @@ static InputStreamReader loadSystemFile(String fileName) throws NullPointerExcep
try {
File file = new File(fileName);
if (file.exists() && file.canRead()) {
try (FileInputStream fis = new FileInputStream(file)) {
return new InputStreamReader(fis, StandardCharsets.UTF_8);
}
FileInputStream fis = new FileInputStream(file);
return new InputStreamReader(fis, StandardCharsets.UTF_8);
}
} catch (Exception e) {
throw new IllegalArgumentException(fileName + " file not found.", e);
Expand Down

0 comments on commit 3b7b811

Please sign in to comment.