Skip to content

Commit

Permalink
Merge branch '2.10' into 2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 17, 2020
2 parents f71a2ac + 7d152c8 commit 47ca693
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.fasterxml.jackson.dataformat.csv.failing;

import java.io.*;
import java.util.Random;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.csv.*;

public class SkipEmptyLines174Test extends ModuleTestBase
{
private final static CsvMapper MAPPER = new CsvMapper();

@JsonPropertyOrder({ "timestamp", "random" })
static class Row {
private int timestamp;
private String random;

public int getTimestamp() {
return timestamp;
}

public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}

public String getRandom() {
return random;
}

public void setRandom(String random) {
this.random = random;
}

@Override
public String toString() {
return "Row{timestamp=" + timestamp + ", random='" + random + "'}";
}
}

public void testEmptyLines174() throws Exception
{
String doc = generateCsvFile();
ObjectReader objectReader = MAPPER
.enable(CsvParser.Feature.SKIP_EMPTY_LINES)
.readerFor(Row.class)
.with(MAPPER.schemaFor(Row.class));
int lineCount = 0;
MappingIterator<Row> iterator = objectReader.readValues(doc);
Row data = null;
while (iterator.hasNext()) {
++lineCount;
try {
data = iterator.next();
} catch (Exception e) {
// System.out.println(lineCount + " : " + data);
fail("Failed on row #"+lineCount+", previous row: "+data);
}
}
iterator.close();
}

private String generateCsvFile() throws Exception {
final StringWriter sw = new StringWriter(50000);
int lineCount = 0;
final Random rnd = new Random();

while (lineCount < 4000) {
sw.append("\"" + System.currentTimeMillis()/1000 + "\",\"" + randomString(rnd) + "\"\n");
++lineCount;
}
return sw.toString();
}

private String randomString(Random rnd) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; ++i) {
sb.append((char) ('A' + (rnd.nextInt() & 0xF)));
}
return sb.toString();
}
}

0 comments on commit 47ca693

Please sign in to comment.