Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ language: java

matrix:
include:
- jdk: oraclejdk11
- jdk: openjdk8
- jdk: openjdk11
- jdk: openjdk14
- jdk: openjdk15
- jdk: openjdk-ea
allow_failures:
- jdk: openjdk-ea
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/csv/CSVFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ public String format(final Object... values) {
final StringWriter out = new StringWriter();
try (CSVPrinter csvPrinter = new CSVPrinter(out, this)) {
csvPrinter.printRecord(values);
String res = out.toString();
int len = recordSeparator != null ? res.length() - recordSeparator.length() : res.length();
final String res = out.toString();
final int len = recordSeparator != null ? res.length() - recordSeparator.length() : res.length();
return res.substring(0, len);
} catch (final IOException e) {
// should not happen because a StringWriter does not do IO.
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/apache/commons/csv/CSVFileParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testCSVFile(final File testFile) throws Exception {
try (final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format)) {
for (final CSVRecord record : parser) {
String parsed = Arrays.toString(record.values());
String comment = record.getComment();
final String comment = record.getComment();
if (checkComments && comment != null) {
parsed += "#" + comment.replace("\n", "\\n");
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public void testCSVUrl(final File testFile) throws Exception {
try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
for (final CSVRecord record : parser) {
String parsed = Arrays.toString(record.values());
String comment = record.getComment();
final String comment = record.getComment();
if (checkComments && comment != null) {
parsed += "#" + comment.replace("\n", "\\n");
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/apache/commons/csv/CSVFormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1216,22 +1216,22 @@ public void testDelimiterSameAsRecordSeparatorThrowsException() {
@Test
public void testWithHeaderEnumNull() {
final CSVFormat format = CSVFormat.DEFAULT;
Class<Enum<?>> simpleName = null;
final Class<Enum<?>> simpleName = null;
format.withHeader(simpleName);
}

@Test
public void testWithHeaderResultSetNull() throws SQLException {
final CSVFormat format = CSVFormat.DEFAULT;
ResultSet resultSet = null;
final ResultSet resultSet = null;
format.withHeader(resultSet);
}

@Test
public void testPrintWithQuoteModeIsNONE() throws IOException {
final Reader in = new StringReader("a,b,c");
final Appendable out = new StringBuilder();
CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE);
final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE);
format.print(in, out, true);
assertEquals("a?,b?,c", out.toString());
}
Expand All @@ -1240,7 +1240,7 @@ public void testPrintWithQuoteModeIsNONE() throws IOException {
public void testPrintWithQuotes() throws IOException {
final Reader in = new StringReader("\"a,b,c\r\nx,y,z");
final Appendable out = new StringBuilder();
CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
format.print(in, out, true);
assertEquals("\"\"\"\"a,b,c\r\nx,y,z\"", out.toString());
}
Expand All @@ -1249,14 +1249,14 @@ public void testPrintWithQuotes() throws IOException {
public void testPrintWithoutQuotes() throws IOException {
final Reader in = new StringReader("");
final Appendable out = new StringBuilder();
CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
format.print(in, out, true);
assertEquals("\"\"", out.toString());
}

@Test
public void testTrim() throws IOException {
CSVFormat formatWithTrim = CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF);
final CSVFormat formatWithTrim = CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF);

CharSequence in = "a,b,c";
final StringBuilder out = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/commons/csv/CSVPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ public void testPrintRecordsWithCSVRecord() throws IOException {
final CharArrayWriter charArrayWriter = new CharArrayWriter(0);
try (final CSVParser parser = CSVFormat.DEFAULT.parse(new StringReader(rowData));
CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
for (CSVRecord record : parser) {
for (final CSVRecord record : parser) {
csvPrinter.printRecord(record);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/apache/commons/csv/CSVRecordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public enum EnumHeader {
SECOND("second"),
THIRD("third");

private String number;
private final String number;

EnumHeader(String number) {
EnumHeader(final String number) {
this.number = number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testJiraCsv149EndWithEOL() throws IOException {
testJiraCsv149EndWithEolAtEof(true);
}

private void testJiraCsv149EndWithEolAtEof(boolean eolAtEof) throws IOException {
private void testJiraCsv149EndWithEolAtEof(final boolean eolAtEof) throws IOException {
String source = "A,B,C,D" + CR_LF + "a1,b1,c1,d1" + CR_LF + "a2,b2,c2,d2";
if (eolAtEof) {
source += CR_LF;
Expand All @@ -44,7 +44,7 @@ private void testJiraCsv149EndWithEolAtEof(boolean eolAtEof) throws IOException
final CSVFormat format = CSVFormat.RFC4180.withFirstRecordAsHeader().withQuote('"');
int lineCounter = 2;
try (final CSVParser parser = new CSVParser(records, format)) {
for (CSVRecord record : parser) {
for (final CSVRecord record : parser) {
assertEquals(lineCounter++, parser.getCurrentLineNumber());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public void testJiraCsv211Format() throws IOException {
final String[] values = new String[] { "1", "Jane Doe", "USA", "" };

final CSVFormat printFormat = CSVFormat.DEFAULT.withDelimiter('\t').withHeader("ID", "Name", "Country", "Age");
String formatted = printFormat.format(values);
final String formatted = printFormat.format(values);
assertEquals("ID\tName\tCountry\tAge\r\n1\tJane Doe\tUSA\t", formatted);

final CSVFormat parseFormat = CSVFormat.DEFAULT.withDelimiter('\t').withFirstRecordAsHeader();
CSVParser parser = parseFormat.parse(new StringReader(formatted));
for (CSVRecord record : parser) {
final CSVParser parser = parseFormat.parse(new StringReader(formatted));
for (final CSVRecord record : parser) {
assertEquals("1", record.get(0));
assertEquals("Jane Doe", record.get(1));
assertEquals("USA", record.get(2));
Expand Down