Skip to content

Commit f7391de

Browse files
committed
Close file handles
1 parent 533eae7 commit f7391de

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/main/java/io/github/moulberry/repo/NEURepoFile.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.io.IOException;
1111
import java.io.InputStream;
12+
import java.io.Reader;
1213
import java.nio.charset.StandardCharsets;
1314
import java.nio.file.Files;
1415
import java.nio.file.Path;
@@ -26,8 +27,8 @@ public String getPath() {
2627
private Path fsPath;
2728

2829
public <T> T json(TypeToken<T> type) throws NEURepositoryException {
29-
try {
30-
return repository.gson.fromJson(Files.newBufferedReader(fsPath, StandardCharsets.UTF_8), type.getType());
30+
try (Reader reader = Files.newBufferedReader(fsPath, StandardCharsets.UTF_8)) {
31+
return repository.gson.fromJson(reader, type.getType());
3132
} catch (IOException | SecurityException e) {
3233
throw new NEURepositoryException(getPath(), "Could not read file", e);
3334
} catch (JsonSyntaxException e) {
@@ -36,8 +37,8 @@ public <T> T json(TypeToken<T> type) throws NEURepositoryException {
3637
}
3738

3839
public <T> T json(Class<T> $class) throws NEURepositoryException {
39-
try {
40-
return repository.gson.fromJson(Files.newBufferedReader(fsPath, StandardCharsets.UTF_8), $class);
40+
try (Reader reader = Files.newBufferedReader(fsPath, StandardCharsets.UTF_8)) {
41+
return repository.gson.fromJson(reader, $class);
4142
} catch (IOException | SecurityException e) {
4243
throw new NEURepositoryException(getPath(), "Could not read file", e);
4344
} catch (JsonSyntaxException e) {

src/main/java/io/github/moulberry/repo/NEURepositoryVersion.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ public class NEURepositoryVersion {
99
public static Properties VERSION_PROPERTIES = new Properties();
1010

1111
static {
12-
InputStream resourceAsStream = NEURepositoryVersion.class.getClassLoader().getResourceAsStream("neurepoparser.properties");
13-
try {
12+
try (InputStream resourceAsStream = NEURepositoryVersion.class.getClassLoader().getResourceAsStream("neurepoparser.properties");) {
1413
VERSION_PROPERTIES.load(resourceAsStream);
1514
} catch (IOException | NullPointerException e) {
1615
new RuntimeException("NEURepositoryVersion could not load neurepoparser.properties.", e).printStackTrace();

0 commit comments

Comments
 (0)