Skip to content

Commit

Permalink
Autoclose csv files properly
Browse files Browse the repository at this point in the history
  • Loading branch information
avandeursen committed Oct 10, 2020
1 parent 079c979 commit 6e64c88
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/sigsoft/sfc/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void loadHotCRPauthors(String fileName) throws IOException {
if (stream == null) {
throw new IOException(String.format("Cannot find csv file %s on class path", fileName));
}
try (var reader = new InputStreamReader(stream)) {
var records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(reader);
try (var reader = new InputStreamReader(stream);
var records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(reader)) {
for (CSVRecord record : records) {
processHotCRPRecord(record);
}
Expand All @@ -49,9 +49,10 @@ public void loadHotCRPauthors(String fileName) throws IOException {
}

public void loadHotCRPauthors(Reader reader) throws IOException {
var records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(reader);
for (CSVRecord record : records) {
processHotCRPRecord(record);
try (var records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(reader)) {
for (CSVRecord record : records) {
processHotCRPRecord(record);
}
}
}

Expand Down

0 comments on commit 6e64c88

Please sign in to comment.