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
12 changes: 6 additions & 6 deletions src/main/java/org/apache/commons/csv/CSVFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,6 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
int start = 0;
int pos = 0;
final int len = value.length();
final int end = len;

final char delimChar = getDelimiter();
final char quoteChar = getQuoteCharacter().charValue();
Expand Down Expand Up @@ -1445,7 +1444,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
// 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;
Expand All @@ -1455,7 +1454,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
}

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 ' '
Expand All @@ -1468,7 +1467,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina

if (!quote) {
// no encapsulation needed - write out the original value
out.append(value, start, end);
out.append(value, start, len);
return;
}
break;
Expand All @@ -1478,7 +1477,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina

if (!quote) {
// no encapsulation needed - write out the original value
out.append(value, start, end);
out.append(value, start, len);
return;
}

Expand All @@ -1487,7 +1486,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina

// 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
Expand All @@ -1507,6 +1506,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
* 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 {

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/csv/CSVBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/csv/CSVFileParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;

Expand Down Expand Up @@ -135,7 +136,7 @@ public void testCSVUrl(final File testFile) throws Exception {

// 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)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one :-)

for (final CSVRecord record : parser) {
String parsed = Arrays.toString(record.values());
final String comment = record.getComment();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/commons/csv/CSVParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public void testGetOneLine() throws IOException {
/**
* 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 {
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 @@ -635,7 +635,7 @@ public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLExc
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");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/apache/commons/csv/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -149,7 +149,7 @@ private static class Stats {
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++;
}

Expand All @@ -158,7 +158,7 @@ private static void show(){
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));
}
Expand Down