Skip to content

Commit 4b1d09a

Browse files
committed
breaking the PR into to two parts by removing the new method
1 parent 2f44a6b commit 4b1d09a

2 files changed

Lines changed: 0 additions & 92 deletions

File tree

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -440,44 +440,6 @@ public CSVParser(final Reader reader, final CSVFormat format, final long charact
440440
this.recordNumber = recordNumber - 1;
441441
}
442442

443-
/**
444-
* Return the parsed CSV content of currently parsed line up until this method is called.
445-
* <p>
446-
* Maximum parsed token length set by the 'maxParsedTokenCount' is considered during the construction of return string.
447-
* </p>
448-
* <p>
449-
* Example:
450-
* </p>
451-
* </p>
452-
* If currently reading CSV record row contains following data and 'maxParsedTokenCount' is set to 5 and current reading position is col7
453-
* </p>
454-
* <pre>
455-
* col1, col2, col3, col4, col5, col6, col7
456-
* </pre>
457-
* <p>
458-
* then method returns following
459-
* </p>
460-
* <pre>
461-
* col3, col4, col5, col6, col7
462-
* </pre>
463-
* @return parsed CSV content of current reading line
464-
*/
465-
public String getLastParsedContent() {
466-
String parsedContent = "";
467-
int recordListSize = this.recordList.size();
468-
if (recordListSize > 0) {
469-
if (recordListSize <= this.maxParsedTokenCount) {
470-
parsedContent = String.join(this.format.getDelimiterString(), this.recordList.toArray(Constants.EMPTY_STRING_ARRAY));
471-
} else {
472-
// number of parsed token exceed required token count. Take the expected tokens from the end.
473-
int startIndex = recordListSize - maxParsedTokenCount;
474-
List<String> lastParsedTokenList = this.recordList.subList(startIndex, recordListSize);
475-
parsedContent = "..." + String.join(this.format.getDelimiterString(), lastParsedTokenList.toArray(Constants.EMPTY_STRING_ARRAY));
476-
}
477-
}
478-
return parsedContent;
479-
}
480-
481443
private void addRecordValue(final boolean lastRecord) {
482444
final String input = this.format.trim(this.reusableToken.content.toString());
483445
if (lastRecord && input.isEmpty() && this.format.getTrailingDelimiter()) {

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,58 +1643,4 @@ private void validateRecordPosition(final String lineSeparator) throws IOExcepti
16431643
parser.close();
16441644
}
16451645

1646-
@Test
1647-
public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_1() throws IOException {
1648-
String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8,col9,col10\n" +
1649-
"rec1,rec2,rec3,rec4,rec5,rec6,rec7,rec8,\"\"rec9\"\",rec10";
1650-
1651-
StringReader stringReader = new StringReader(csvContent);
1652-
CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
1653-
.setHeader()
1654-
.setSkipHeaderRecord(true)
1655-
.build();
1656-
1657-
CSVParser csvParser = csvFormat.parse(stringReader);
1658-
Exception exception = assertThrows(UncheckedIOException.class, () -> {
1659-
for (CSVRecord record : csvParser) {
1660-
String content = record.get(0) + " " + record.get(1) + " " + record.get(2) + " " + record.get(3)
1661-
+ " " + record.get(4) + " " + record.get(5) + " " + record.get(6) + " " + record.get(7)
1662-
+ " " + record.get(8) + " " + record.get(9);
1663-
assertNotNull(content);
1664-
}
1665-
});
1666-
String expectedErrorMessage = "Exception reading next record: java.io.IOException: Exception during parsing at " +
1667-
"line: 2, position: 94";
1668-
String actualMessage = exception.getMessage();
1669-
assertTrue(actualMessage.contains(expectedErrorMessage));
1670-
String expectedLastParsedContent = "...rec4,rec5,rec6,rec7,rec8";
1671-
assertEquals(expectedLastParsedContent, csvParser.getLastParsedContent());
1672-
}
1673-
1674-
@Test
1675-
public void testFaultyCSVShouldThrowErrorAndDetailedMessageShouldBeAvailable_2() throws IOException {
1676-
String csvContent = "col1,col2,col3,col4,col5,col6,col7,col8\n" +
1677-
"rec1,rec2,rec3,rec4,\"\"rec5\"\",rec6,rec7,rec8";
1678-
1679-
StringReader stringReader = new StringReader(csvContent);
1680-
CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
1681-
.setHeader()
1682-
.setSkipHeaderRecord(true)
1683-
.build();
1684-
1685-
CSVParser csvParser = csvFormat.parse(stringReader);
1686-
Exception exception = assertThrows(UncheckedIOException.class, () -> {
1687-
for (CSVRecord record : csvParser) {
1688-
String content = record.get(0) + " " + record.get(1) + " " + record.get(2) + " " + record.get(3)
1689-
+ " " + record.get(4) + " " + record.get(5) + " " + record.get(6) + " " + record.get(7);
1690-
assertNotNull(content);
1691-
}
1692-
});
1693-
String expectedErrorMessage = "Exception reading next record: java.io.IOException: Exception during parsing at " +
1694-
"line: 2, position: 63";
1695-
String actualMessage = exception.getMessage();
1696-
assertTrue(actualMessage.contains(expectedErrorMessage));
1697-
String expectedLastParsedContent = "rec1,rec2,rec3,rec4";
1698-
assertEquals(expectedLastParsedContent, csvParser.getLastParsedContent());
1699-
}
17001646
}

0 commit comments

Comments
 (0)