Minor Improvement: (#127)
* Add final * Unnecessary semicolon '' * Use StandardCharsets * Fix javadoc
This commit is contained in:
parent
8e953c0c17
commit
d580c90f73
|
@ -1402,7 +1402,6 @@ public final class CSVFormat implements Serializable {
|
|||
int start = 0;
|
||||
int pos = 0;
|
||||
final int len = value.length();
|
||||
final int end = len;
|
||||
|
||||
final char delimChar = getDelimiter();
|
||||
final char quoteChar = getQuoteCharacter().charValue();
|
||||
|
@ -1445,7 +1444,7 @@ public final class CSVFormat implements Serializable {
|
|||
// by including the default comment char too.
|
||||
quote = true;
|
||||
} else {
|
||||
while (pos < end) {
|
||||
while (pos < len) {
|
||||
c = value.charAt(pos);
|
||||
if (c == LF || c == CR || c == quoteChar || c == delimChar || c == escapeChar) {
|
||||
quote = true;
|
||||
|
@ -1455,7 +1454,7 @@ public final class CSVFormat implements Serializable {
|
|||
}
|
||||
|
||||
if (!quote) {
|
||||
pos = end - 1;
|
||||
pos = len - 1;
|
||||
c = value.charAt(pos);
|
||||
// Some other chars at the end caused the parser to fail, so for now
|
||||
// encapsulate if we end in anything less than ' '
|
||||
|
@ -1468,7 +1467,7 @@ public final class CSVFormat implements Serializable {
|
|||
|
||||
if (!quote) {
|
||||
// no encapsulation needed - write out the original value
|
||||
out.append(value, start, end);
|
||||
out.append(value, start, len);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -1478,7 +1477,7 @@ public final class CSVFormat implements Serializable {
|
|||
|
||||
if (!quote) {
|
||||
// no encapsulation needed - write out the original value
|
||||
out.append(value, start, end);
|
||||
out.append(value, start, len);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1487,7 +1486,7 @@ public final class CSVFormat implements Serializable {
|
|||
|
||||
// Pick up where we left off: pos should be positioned on the first character that caused
|
||||
// the need for encapsulation.
|
||||
while (pos < end) {
|
||||
while (pos < len) {
|
||||
final char c = value.charAt(pos);
|
||||
if (c == quoteChar || c == escapeChar) {
|
||||
// write out the chunk up until this point
|
||||
|
@ -1507,6 +1506,7 @@ public final class CSVFormat implements Serializable {
|
|||
* Always use quotes unless QuoteMode is NONE, so we not have to look ahead.
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
private void printWithQuotes(final Reader reader, final Appendable out) throws IOException {
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
@ -63,7 +64,7 @@ public class CSVBenchmark {
|
|||
public void init() throws IOException {
|
||||
final File file = new File("src/test/resources/perf/worldcitiespop.txt.gz");
|
||||
final InputStream in = new GZIPInputStream(new FileInputStream(file));
|
||||
this.data = IOUtils.toString(in, "ISO-8859-1");
|
||||
this.data = IOUtils.toString(in, StandardCharsets.ISO_8859_1);
|
||||
in.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.io.FilenameFilter;
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -135,7 +136,7 @@ public class CSVFileParserTest {
|
|||
|
||||
// Now parse the file and compare against the expected results
|
||||
final URL resource = ClassLoader.getSystemResource("org/apache/commons/csv/CSVFileParser/" + split[0]);
|
||||
try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
|
||||
try (final CSVParser parser = CSVParser.parse(resource, StandardCharsets.UTF_8, format)) {
|
||||
for (final CSVRecord record : parser) {
|
||||
String parsed = Arrays.toString(record.values());
|
||||
final String comment = record.getComment();
|
||||
|
|
|
@ -572,7 +572,7 @@ public class CSVParserTest {
|
|||
/**
|
||||
* Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110].
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException when an I/O error occurs.
|
||||
*/
|
||||
@Test
|
||||
public void testGetOneLineOneParser() throws IOException {
|
||||
|
|
|
@ -635,7 +635,7 @@ public class CSVPrinterTest {
|
|||
public void testJdbcPrinterWithResultSet() throws IOException, ClassNotFoundException, SQLException {
|
||||
final StringWriter sw = new StringWriter();
|
||||
Class.forName("org.h2.Driver");
|
||||
try (final Connection connection = geH2Connection();) {
|
||||
try (final Connection connection = geH2Connection()) {
|
||||
setUpTable(connection);
|
||||
try (final Statement stmt = connection.createStatement();
|
||||
final ResultSet resultSet = stmt.executeQuery("select ID, NAME, TEXT from TEST");
|
||||
|
|
|
@ -64,7 +64,7 @@ public class PerformanceTest {
|
|||
private static int max = 11; // skip first test
|
||||
|
||||
private static int num = 0; // number of elapsed times recorded
|
||||
private static long[] elapsedTimes = new long[max];
|
||||
private static final long[] ELAPSED_TIMES = new long[max];
|
||||
|
||||
private static final CSVFormat format = CSVFormat.EXCEL;
|
||||
|
||||
|
@ -149,7 +149,7 @@ public class PerformanceTest {
|
|||
private static void show(final String msg, final Stats s, final long start) {
|
||||
final long elapsed = System.currentTimeMillis() - start;
|
||||
System.out.printf("%-20s: %5dms %d lines %d fields%n", msg, elapsed, s.count, s.fields);
|
||||
elapsedTimes[num] = elapsed;
|
||||
ELAPSED_TIMES[num] = elapsed;
|
||||
num++;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ public class PerformanceTest {
|
|||
if (num > 1) {
|
||||
long tot = 0;
|
||||
for (int i = 1; i < num; i++) { // skip first test
|
||||
tot += elapsedTimes[i];
|
||||
tot += ELAPSED_TIMES[i];
|
||||
}
|
||||
System.out.printf("%-20s: %5dms%n%n", "Average(not first)", tot / (num - 1));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue