99
1010import java .io .IOException ;
1111import java .io .InputStream ;
12+ import java .io .Reader ;
1213import java .nio .charset .StandardCharsets ;
1314import java .nio .file .Files ;
1415import 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 ) {
0 commit comments