Skip to content
Permalink
Browse files
CSV-267 - Minor improvement (#126)
  • Loading branch information
arturobernalg committed Dec 12, 2020
1 parent e5fbba3 commit 64bae1731766dfba45eec76b26e4af837b24effa
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
@@ -1051,7 +1051,7 @@ public boolean getTrailingDelimiter() {
/**
* Returns whether to trim leading and trailing blanks.
* This is used by {@link #print(Object, Appendable, boolean)}
* Also by {@link CSVParser#addRecordValue(boolean)}
* Also by {CSVParser#addRecordValue(boolean)}
*
* @return whether to trim leading and trailing blanks.
*/
@@ -1322,8 +1322,7 @@ public void printRecord(final Appendable out, final Object... values) throws IOE
private void printWithEscapes(final CharSequence value, final Appendable out) throws IOException {
int start = 0;
int pos = 0;
final int len = value.length();
final int end = len;
final int end = value.length();

final char delim = getDelimiter();
final char escape = getEscapeCharacter().charValue();
@@ -179,7 +179,7 @@ private String randStr() {
final char[] buf = new char[sz];
for (int i = 0; i < sz; i++) {
// stick in special chars with greater frequency
char ch;
final char ch;
final int what = r.nextInt(20);
switch (what) {
case 0:
@@ -1342,7 +1342,7 @@ public void testPrintRecordsWithCSVRecord() throws IOException {
final String rowData = StringUtils.join(values, ',');
final CharArrayWriter charArrayWriter = new CharArrayWriter(0);
try (final CSVParser parser = CSVFormat.DEFAULT.parse(new StringReader(rowData));
CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
final CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
for (final CSVRecord record : parser) {
csvPrinter.printRecord(record);
}
@@ -31,7 +31,6 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -213,7 +212,7 @@ public void testRemoveAndAddColumns() throws IOException {

@Test
public void testSerialization() throws IOException, ClassNotFoundException {
CSVRecord shortRec;
final CSVRecord shortRec;
try (final CSVParser parser = CSVParser.parse("A,B\n#my comment\nOne,Two", CSVFormat.DEFAULT.withHeader().withCommentMarker('#'))) {
shortRec = parser.iterator().next();
}
@@ -88,7 +88,7 @@ public static void main(final String [] args) throws Exception {
max = Integer.parseInt(args[0]);
}

String tests[];
final String[] tests;
if (argc > 1) {
tests = new String[argc - 1];
for (int i = 1; i < argc; i++) {
@@ -39,8 +39,9 @@ private Utils() {
* @param actual the List of {@link CSVRecord} entries, each containing an array of values
*/
public static void compare(final String message, final String[][] expected, final List<CSVRecord> actual) {
assertEquals(expected.length, actual.size(), message + " - outer array size");
for (int i = 0; i < expected.length; i++) {
final int expectedLength = expected.length;
assertEquals(expectedLength, actual.size(), message + " - outer array size");
for (int i = 0; i < expectedLength; i++) {
assertArrayEquals(expected[i], actual.get(i).values(), message + " (entry " + i + ")");
}
}
@@ -22,6 +22,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
@@ -37,7 +38,7 @@ public void test() throws UnsupportedEncodingException, IOException {
final InputStream pointsOfReference = getClass().getResourceAsStream("/org/apache/commons/csv/CSV-198/optd_por_public.csv");
assertNotNull(pointsOfReference);
try (@SuppressWarnings("resource")
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) {
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, StandardCharsets.UTF_8))) {
for (final CSVRecord record : parser) {
final String locationType = record.get("location_type");
assertNotNull(locationType);
@@ -46,7 +46,7 @@ public void testJiraCsv248() throws IOException, ClassNotFoundException {
// CSVRecord rec = parser.iterator().next();
//}
try (InputStream in = getTestInput();
ObjectInputStream ois = new ObjectInputStream(in)) {
final ObjectInputStream ois = new ObjectInputStream(in)) {
final Object object = ois.readObject();
assertTrue(object instanceof CSVRecord);
final CSVRecord rec = (CSVRecord) object;
@@ -40,7 +40,7 @@ public void testJiraCsv249() throws IOException {
printer.printRecord("foo \\", "bar");
}
final StringReader stringReader = new StringReader(stringWriter.toString());
List<CSVRecord> records;
final List<CSVRecord> records;
try (CSVParser parser = new CSVParser(stringReader, csvFormat)) {
records = parser.getRecords();
}
@@ -203,11 +203,12 @@ public void printComment(final String comment) throws IOException {
}
out.append(format.getCommentMarker().charValue());
out.append(SP);
for (int i = 0; i < comment.length(); i++) {
final int commentLength = comment.length();
for (int i = 0; i < commentLength; i++) {
final char c = comment.charAt(i);
switch (c) {
case CR:
if (i + 1 < comment.length() && comment.charAt(i + 1) == LF) {
if (i + 1 < commentLength && comment.charAt(i + 1) == LF) {
i++;
}
//$FALL-THROUGH$ break intentionally excluded.

0 comments on commit 64bae17

Please sign in to comment.