Skip to content

Commit

Permalink
Better resource management.
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jul 9, 2021
1 parent 5506bdb commit e06b845
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -35,7 +35,7 @@ public class JiraCsv167Test {
public void parse() throws IOException {
int totcomment = 0;
int totrecs = 0;
try (final BufferedReader br = new BufferedReader(getTestInput())) {
try (final Reader reader = getTestReader(); final BufferedReader br = new BufferedReader(reader)) {
String s = null;
boolean lastWasComment = false;
while ((s = br.readLine()) != null) {
Expand Down Expand Up @@ -69,7 +69,7 @@ public void parse() throws IOException {
// @formatter:on
int comments = 0;
int records = 0;
try (final CSVParser parser = format.parse(getTestInput())) {
try (final Reader reader = getTestReader(); final CSVParser parser = format.parse(reader)) {
for (final CSVRecord csvRecord : parser) {
records++;
if (csvRecord.hasComment()) {
Expand All @@ -82,7 +82,7 @@ public void parse() throws IOException {
assertEquals(totrecs, records); // records includes the header
}

private Reader getTestInput() {
private Reader getTestReader() {
return new InputStreamReader(
ClassLoader.getSystemClassLoader().getResourceAsStream("org/apache/commons/csv/csv-167/sample1.csv"));
}
Expand Down

0 comments on commit e06b845

Please sign in to comment.