Skip to content

Commit ebf09ad

Browse files
committed
fix(routing): fix handling of empty lines
1 parent b8e1def commit ebf09ad

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

lib/mosaic-routing/src/main/java/com/csvreader/CsvReader.java

+10-21
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
import com.opencsv.CSVParserBuilder;
1919
import com.opencsv.CSVReader;
2020
import com.opencsv.CSVReaderBuilder;
21-
import com.opencsv.exceptions.CsvValidationException;
22-
import com.opencsv.validators.LineValidator;
2321
import org.apache.commons.lang3.StringUtils;
2422
import org.apache.commons.lang3.Validate;
2523

24+
import java.io.IOException;
2625
import java.io.InputStream;
2726
import java.io.InputStreamReader;
2827
import java.io.Reader;
@@ -55,15 +54,20 @@ public CsvReader(Reader openCsvReader) {
5554
public CsvReader(Reader openCsvReader, char delimiter) {
5655
this.openCsvReader = new CSVReaderBuilder(openCsvReader)
5756
.withCSVParser(new CSVParserBuilder().withSeparator(delimiter).build())
58-
.withLineValidator(new IgnoreEmptyLines())
5957
.build();
6058
}
6159

6260
public boolean readRecord() {
6361
try {
64-
currenRecord = this.openCsvReader.readNext();
65-
return currenRecord != null;
66-
} catch (Exception e) {
62+
do {
63+
currenRecord = this.openCsvReader.readNextSilently();
64+
if (currenRecord == null) {
65+
return false;
66+
}
67+
} while (currenRecord.length == 1 && StringUtils.isEmpty(currenRecord[0]));
68+
return true;
69+
} catch (IOException e) {
70+
currenRecord = null;
6771
return false;
6872
}
6973
}
@@ -91,19 +95,4 @@ public String get(String column) {
9195
? currenRecord[index]
9296
: "";
9397
}
94-
95-
private static class IgnoreEmptyLines implements LineValidator {
96-
97-
@Override
98-
public boolean isValid(String s) {
99-
return StringUtils.isNotEmpty(s);
100-
}
101-
102-
@Override
103-
public void validate(String s) throws CsvValidationException {
104-
if (!isValid(s)) {
105-
throw new CsvValidationException();
106-
}
107-
}
108-
}
10998
}

0 commit comments

Comments
 (0)