formatting changes
This commit is contained in:
parent
b4abb0155e
commit
f0391ea0d3
|
@ -464,11 +464,11 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
||||||
* </pre>
|
* </pre>
|
||||||
* @return parsed CSV content of current reading line
|
* @return parsed CSV content of current reading line
|
||||||
*/
|
*/
|
||||||
private String getLastParsedContent(){
|
private String getLastParsedContent() {
|
||||||
String parsedContent = "";
|
String parsedContent = "";
|
||||||
int recordListSize = this.recordList.size();
|
int recordListSize = this.recordList.size();
|
||||||
if(recordListSize > 0) {
|
if (recordListSize > 0) {
|
||||||
if(recordListSize <= this.maxParsedTokenCount) {
|
if (recordListSize <= this.maxParsedTokenCount) {
|
||||||
parsedContent = String.join("", this.recordList.toArray(Constants.EMPTY_STRING_ARRAY));
|
parsedContent = String.join("", this.recordList.toArray(Constants.EMPTY_STRING_ARRAY));
|
||||||
} else {
|
} else {
|
||||||
// number of parsed token exceed required token count. Take the expected tokens from the end.
|
// number of parsed token exceed required token count. Take the expected tokens from the end.
|
||||||
|
@ -808,9 +808,9 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
|
||||||
do {
|
do {
|
||||||
this.reusableToken.reset();
|
this.reusableToken.reset();
|
||||||
// https://issues.apache.org/jira/browse/CSV-147
|
// https://issues.apache.org/jira/browse/CSV-147
|
||||||
try{
|
try {
|
||||||
this.lexer.nextToken(this.reusableToken);
|
this.lexer.nextToken(this.reusableToken);
|
||||||
} catch (IOException ioe){
|
} catch (IOException ioe) {
|
||||||
String errorMessage = "An error occurred while tying to parse the CSV content. Error in line: "
|
String errorMessage = "An error occurred while tying to parse the CSV content. Error in line: "
|
||||||
+ this.lexer.getCurrentLineNumber() + ", position: " + this.lexer.getCharacterPosition()
|
+ this.lexer.getCurrentLineNumber() + ", position: " + this.lexer.getCharacterPosition()
|
||||||
+ ", last parsed content: " + this.getLastParsedContent();
|
+ ", last parsed content: " + this.getLastParsedContent();
|
||||||
|
|
|
@ -1644,7 +1644,6 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFaultyCSVShouldThrowErrorWithDetailedMessage() {
|
public void testFaultyCSVShouldThrowErrorWithDetailedMessage() {
|
||||||
|
|
||||||
String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n" +
|
String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n" +
|
||||||
"rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\"\"rec9\"\",rec10";
|
"rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\"\"rec9\"\",rec10";
|
||||||
|
|
||||||
|
@ -1654,18 +1653,20 @@ public class CSVParserTest {
|
||||||
.setSkipHeaderRecord(true)
|
.setSkipHeaderRecord(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Exception exception = assertThrows(UncheckedIOException.class, ()-> {
|
Exception exception = assertThrows(UncheckedIOException.class, () -> {
|
||||||
Iterable<CSVRecord> records = csvFormat.parse(stringReader);
|
Iterable<CSVRecord> records = csvFormat.parse(stringReader);
|
||||||
for (CSVRecord record : records) {
|
for (CSVRecord record : records) {
|
||||||
System.out.println(record.get(0) + " " + record.get(1) + " " + record.get(2) + " " + record.get(3) + " " + record.get(4) + " " + record.get(5) + " " + record.get(6) + " " + record.get(7) + " " + record.get(8) + " " + record.get(9));
|
System.out.println(record.get(0) + " " + record.get(1) + " " + record.get(2) + " " + record.get(3)
|
||||||
|
+ " " + record.get(4) + " " + record.get(5) + " " + record.get(6) + " " + record.get(7)
|
||||||
|
+ " " + record.get(8) + " " + record.get(9));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
String expectedErrorMessage = "IOException reading next record: java.io.IOException: An error occurred while tying to parse the CSV content. Error in line: 2, position: 94, last parsed content: ...rec4,rec5,rec6,rec7,rec8";
|
String expectedErrorMessage = "IOException reading next record: java.io.IOException: An error occurred while " +
|
||||||
|
"tying to parse the CSV content. Error in line: 2, position: 94, last parsed content: " +
|
||||||
|
"...rec4,rec5,rec6,rec7,rec8";
|
||||||
String actualMessage = exception.getMessage();
|
String actualMessage = exception.getMessage();
|
||||||
|
|
||||||
assertTrue(actualMessage.contains(expectedErrorMessage));
|
assertTrue(actualMessage.contains(expectedErrorMessage));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue