Rename methods that create a builder newBuilder().
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1409455 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6a34b823c8
commit
7ac5dd3ec6
|
@ -62,7 +62,7 @@ public class CSVFormat implements Serializable {
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public static final CSVFormat RFC4180 =
|
public static final CSVFormat RFC4180 =
|
||||||
defaults()
|
newBuilder()
|
||||||
.withIgnoreEmptyLines(false)
|
.withIgnoreEmptyLines(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class CSVFormat implements Serializable {
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public static final CSVFormat DEFAULT = // TODO rename to something more meaningful
|
public static final CSVFormat DEFAULT = // TODO rename to something more meaningful
|
||||||
defaults()
|
newBuilder()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,13 +97,13 @@ public class CSVFormat implements Serializable {
|
||||||
* Note: this is currently the same as RFC4180
|
* Note: this is currently the same as RFC4180
|
||||||
*/
|
*/
|
||||||
public static final CSVFormat EXCEL =
|
public static final CSVFormat EXCEL =
|
||||||
defaults()
|
newBuilder()
|
||||||
.withIgnoreEmptyLines(false)
|
.withIgnoreEmptyLines(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
/** Tab-delimited format, with quote; leading and trailing spaces ignored. */
|
/** Tab-delimited format, with quote; leading and trailing spaces ignored. */
|
||||||
public static final CSVFormat TDF =
|
public static final CSVFormat TDF =
|
||||||
defaults()
|
newBuilder()
|
||||||
.withDelimiter(TAB)
|
.withDelimiter(TAB)
|
||||||
.withIgnoreSurroundingSpaces(true)
|
.withIgnoreSurroundingSpaces(true)
|
||||||
.build();
|
.build();
|
||||||
|
@ -117,7 +117,7 @@ public class CSVFormat implements Serializable {
|
||||||
* http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
|
* http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
|
||||||
*/
|
*/
|
||||||
public static final CSVFormat MYSQL =
|
public static final CSVFormat MYSQL =
|
||||||
defaults()
|
newBuilder()
|
||||||
.withDelimiter(TAB)
|
.withDelimiter(TAB)
|
||||||
.withQuoteChar(null)
|
.withQuoteChar(null)
|
||||||
.withEscape(ESCAPE)
|
.withEscape(ESCAPE)
|
||||||
|
@ -126,13 +126,13 @@ public class CSVFormat implements Serializable {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for creating CSV formats.
|
* Creates a new CSV format builds.
|
||||||
*
|
*
|
||||||
* @param delimiter
|
* @param delimiter
|
||||||
* the char used for value separation, must not be a line break character
|
* the char used for value separation, must not be a line break character
|
||||||
* @throws IllegalArgumentException if the delimiter is a line break character
|
* @throws IllegalArgumentException if the delimiter is a line break character
|
||||||
*/
|
*/
|
||||||
public static CSVFormatBuilder newFormat(char delimiter) {
|
public static CSVFormatBuilder newBuilder(char delimiter) {
|
||||||
return new CSVFormatBuilder(delimiter);
|
return new CSVFormatBuilder(delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ public class CSVFormat implements Serializable {
|
||||||
* <li>withLineSeparator(CRLF)</li>
|
* <li>withLineSeparator(CRLF)</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public static CSVFormatBuilder defaults() {
|
public static CSVFormatBuilder newBuilder() {
|
||||||
return new CSVFormatBuilder(COMMA, DOUBLE_QUOTE, null, null, null, false, true, CRLF, null);
|
return new CSVFormatBuilder(COMMA, DOUBLE_QUOTE, null, null, null, false, true, CRLF, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class CSVFileParserTest {
|
||||||
assertTrue(testName+" require 1 param", split.length >= 1);
|
assertTrue(testName+" require 1 param", split.length >= 1);
|
||||||
// first line starts with csv data file name
|
// first line starts with csv data file name
|
||||||
final BufferedReader csvFile = new BufferedReader(new FileReader(new File(BASE, split[0])));
|
final BufferedReader csvFile = new BufferedReader(new FileReader(new File(BASE, split[0])));
|
||||||
CSVFormatBuilder builder = CSVFormat.newFormat(',').withQuoteChar('"');
|
CSVFormatBuilder builder = CSVFormat.newBuilder(',').withQuoteChar('"');
|
||||||
CSVFormat fmt = builder.build();
|
CSVFormat fmt = builder.build();
|
||||||
boolean checkComments = false;
|
boolean checkComments = false;
|
||||||
for(int i=1; i < split.length; i++) {
|
for(int i=1; i < split.length; i++) {
|
||||||
|
|
|
@ -45,12 +45,12 @@ public class CSVFormatBuilderTest {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testNewFormatLFThrowsException() {
|
public void testNewFormatLFThrowsException() {
|
||||||
CSVFormat.newFormat(LF);
|
CSVFormat.newBuilder(LF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testNewFormatCRThrowsException() {
|
public void testNewFormatCRThrowsException() {
|
||||||
CSVFormat.newFormat(CR);
|
CSVFormat.newBuilder(CR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
@ -101,7 +101,7 @@ public class CSVFormatBuilderTest {
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
|
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
|
||||||
CSVFormat.newFormat('!').withQuotePolicy(Quote.NONE).build();
|
CSVFormat.newBuilder('!').withQuotePolicy(Quote.NONE).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class CSVLexerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNextToken1() throws IOException {
|
public void testNextToken1() throws IOException {
|
||||||
final String code = "abc,def, hijk, lmnop, qrst,uv ,wxy ,z , ,";
|
final String code = "abc,def, hijk, lmnop, qrst,uv ,wxy ,z , ,";
|
||||||
final Lexer parser = getLexer(code, CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
|
final Lexer parser = getLexer(code, CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
|
||||||
assertTokenEquals(TOKEN, "abc", parser.nextToken(new Token()));
|
assertTokenEquals(TOKEN, "abc", parser.nextToken(new Token()));
|
||||||
assertTokenEquals(TOKEN, "def", parser.nextToken(new Token()));
|
assertTokenEquals(TOKEN, "def", parser.nextToken(new Token()));
|
||||||
assertTokenEquals(TOKEN, "hijk", parser.nextToken(new Token()));
|
assertTokenEquals(TOKEN, "hijk", parser.nextToken(new Token()));
|
||||||
|
@ -83,7 +83,7 @@ public class CSVLexerTest {
|
||||||
"\n"+
|
"\n"+
|
||||||
"\n"+
|
"\n"+
|
||||||
"# Final comment\n"; // 7
|
"# Final comment\n"; // 7
|
||||||
final CSVFormat format = CSVFormat.defaults().withCommentStart('#').build();
|
final CSVFormat format = CSVFormat.newBuilder().withCommentStart('#').build();
|
||||||
assertTrue("Should ignore empty lines", format.getIgnoreEmptyLines());
|
assertTrue("Should ignore empty lines", format.getIgnoreEmptyLines());
|
||||||
|
|
||||||
final Lexer parser = getLexer(code, format);
|
final Lexer parser = getLexer(code, format);
|
||||||
|
@ -126,7 +126,7 @@ public class CSVLexerTest {
|
||||||
"\n"+ // 6b
|
"\n"+ // 6b
|
||||||
"\n"+ // 6c
|
"\n"+ // 6c
|
||||||
"# Final comment\n"; // 7
|
"# Final comment\n"; // 7
|
||||||
final CSVFormat format = CSVFormat.defaults().withCommentStart('#').withIgnoreEmptyLines(false).build();
|
final CSVFormat format = CSVFormat.newBuilder().withCommentStart('#').withIgnoreEmptyLines(false).build();
|
||||||
assertFalse("Should not ignore empty lines", format.getIgnoreEmptyLines());
|
assertFalse("Should not ignore empty lines", format.getIgnoreEmptyLines());
|
||||||
|
|
||||||
final Lexer parser = getLexer(code, format);
|
final Lexer parser = getLexer(code, format);
|
||||||
|
@ -187,7 +187,7 @@ public class CSVLexerTest {
|
||||||
* \,,
|
* \,,
|
||||||
*/
|
*/
|
||||||
final String code = "a,\\,,b\\\\\n\\,,\\\nc,d\\\r\ne";
|
final String code = "a,\\,,b\\\\\n\\,,\\\nc,d\\\r\ne";
|
||||||
final CSVFormat format = CSVFormat.defaults().withEscape('\\').withIgnoreEmptyLines(false).build();
|
final CSVFormat format = CSVFormat.newBuilder().withEscape('\\').withIgnoreEmptyLines(false).build();
|
||||||
assertTrue(format.isEscaping());
|
assertTrue(format.isEscaping());
|
||||||
final Lexer parser = getLexer(code, format);
|
final Lexer parser = getLexer(code, format);
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ public class CSVLexerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNextToken3BadEscaping() throws IOException {
|
public void testNextToken3BadEscaping() throws IOException {
|
||||||
final String code = "a,b,c\\";
|
final String code = "a,b,c\\";
|
||||||
final CSVFormat format = CSVFormat.defaults().withEscape('\\').build();
|
final CSVFormat format = CSVFormat.newBuilder().withEscape('\\').build();
|
||||||
assertTrue(format.isEscaping());
|
assertTrue(format.isEscaping());
|
||||||
final Lexer parser = getLexer(code, format);
|
final Lexer parser = getLexer(code, format);
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ public class CSVLexerTest {
|
||||||
* a, " foo " ,b
|
* a, " foo " ,b
|
||||||
*/
|
*/
|
||||||
final String code = "a,\"foo\",b\na, \" foo\",b\na,\"foo \" ,b\na, \" foo \" ,b";
|
final String code = "a,\"foo\",b\na, \" foo\",b\na,\"foo \" ,b\na, \" foo \" ,b";
|
||||||
final Lexer parser = getLexer(code, CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
|
final Lexer parser = getLexer(code, CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
|
||||||
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
|
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
|
||||||
assertTokenEquals(TOKEN, "foo", parser.nextToken(new Token()));
|
assertTokenEquals(TOKEN, "foo", parser.nextToken(new Token()));
|
||||||
assertTokenEquals(EORECORD, "b", parser.nextToken(new Token()));
|
assertTokenEquals(EORECORD, "b", parser.nextToken(new Token()));
|
||||||
|
@ -264,7 +264,7 @@ public class CSVLexerTest {
|
||||||
* ;;
|
* ;;
|
||||||
*/
|
*/
|
||||||
final String code = "a;'b and '' more\n'\n!comment;;;;\n;;";
|
final String code = "a;'b and '' more\n'\n!comment;;;;\n;;";
|
||||||
final CSVFormat format = CSVFormat.defaults().withDelimiter(';').withQuoteChar('\'').withCommentStart('!').build();
|
final CSVFormat format = CSVFormat.newBuilder().withDelimiter(';').withQuoteChar('\'').withCommentStart('!').build();
|
||||||
final Lexer parser = getLexer(code, format);
|
final Lexer parser = getLexer(code, format);
|
||||||
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
|
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
|
||||||
assertTokenEquals(EORECORD, "b and ' more\n", parser.nextToken(new Token()));
|
assertTokenEquals(EORECORD, "b and ' more\n", parser.nextToken(new Token()));
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLine() throws IOException {
|
public void testGetLine() throws IOException {
|
||||||
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
|
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
|
||||||
for (final String[] re : RESULT) {
|
for (final String[] re : RESULT) {
|
||||||
assertArrayEquals(re, parser.nextRecord().values());
|
assertArrayEquals(re, parser.nextRecord().values());
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRecords() throws IOException {
|
public void testGetRecords() throws IOException {
|
||||||
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
|
final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
|
||||||
final List<CSVRecord> records = parser.getRecords();
|
final List<CSVRecord> records = parser.getRecords();
|
||||||
assertEquals(RESULT.length, records.size());
|
assertEquals(RESULT.length, records.size());
|
||||||
assertTrue(records.size() > 0);
|
assertTrue(records.size() > 0);
|
||||||
|
@ -312,7 +312,7 @@ public class CSVParserTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
final CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('\'').withEscape('/')
|
final CSVFormat format = CSVFormat.newBuilder(',').withQuoteChar('\'').withEscape('/')
|
||||||
.withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
|
.withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
|
||||||
|
|
||||||
final CSVParser parser = new CSVParser(code, format);
|
final CSVParser parser = new CSVParser(code, format);
|
||||||
|
@ -342,7 +342,7 @@ public class CSVParserTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
final CSVFormat format = CSVFormat.newFormat(',').withEscape('/')
|
final CSVFormat format = CSVFormat.newBuilder(',').withEscape('/')
|
||||||
.withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
|
.withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
|
||||||
|
|
||||||
final CSVParser parser = new CSVParser(code, format);
|
final CSVParser parser = new CSVParser(code, format);
|
||||||
|
@ -381,7 +381,7 @@ public class CSVParserTest {
|
||||||
{"\n", " ", "#"},
|
{"\n", " ", "#"},
|
||||||
};
|
};
|
||||||
|
|
||||||
format = CSVFormat.defaults().withCommentStart('#').build();
|
format = CSVFormat.newBuilder().withCommentStart('#').build();
|
||||||
parser = new CSVParser(code, format);
|
parser = new CSVParser(code, format);
|
||||||
records = parser.getRecords();
|
records = parser.getRecords();
|
||||||
|
|
||||||
|
@ -481,7 +481,7 @@ public class CSVParserTest {
|
||||||
public void testHeader() throws Exception {
|
public void testHeader() throws Exception {
|
||||||
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
|
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
|
||||||
|
|
||||||
final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader().build().parse(in).iterator();
|
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader().build().parse(in).iterator();
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
assertTrue(records.hasNext());
|
assertTrue(records.hasNext());
|
||||||
|
@ -498,7 +498,7 @@ public class CSVParserTest {
|
||||||
public void testHeaderComment() throws Exception {
|
public void testHeaderComment() throws Exception {
|
||||||
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
|
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
|
||||||
|
|
||||||
final Iterator<CSVRecord> records = CSVFormat.defaults().withCommentStart('#').withHeader().build().parse(in).iterator();
|
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withCommentStart('#').withHeader().build().parse(in).iterator();
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
assertTrue(records.hasNext());
|
assertTrue(records.hasNext());
|
||||||
|
@ -515,7 +515,7 @@ public class CSVParserTest {
|
||||||
public void testProvidedHeader() throws Exception {
|
public void testProvidedHeader() throws Exception {
|
||||||
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
|
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
|
||||||
|
|
||||||
final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader("A", "B", "C").build().parse(in).iterator();
|
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader("A", "B", "C").build().parse(in).iterator();
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
assertTrue(records.hasNext());
|
assertTrue(records.hasNext());
|
||||||
|
@ -536,7 +536,7 @@ public class CSVParserTest {
|
||||||
public void testMappedButNotSetAsOutlook2007ContactExport() throws Exception {
|
public void testMappedButNotSetAsOutlook2007ContactExport() throws Exception {
|
||||||
final Reader in = new StringReader("a,b,c\n1,2\nx,y,z");
|
final Reader in = new StringReader("a,b,c\n1,2\nx,y,z");
|
||||||
|
|
||||||
final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader("A", "B", "C").build().parse(in).iterator();
|
final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader("A", "B", "C").build().parse(in).iterator();
|
||||||
|
|
||||||
// header record
|
// header record
|
||||||
assertTrue(records.hasNext());
|
assertTrue(records.hasNext());
|
||||||
|
@ -578,7 +578,7 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetHeaderMap() throws Exception {
|
public void testGetHeaderMap() throws Exception {
|
||||||
final CSVParser parser = new CSVParser("a,b,c\n1,2,3\nx,y,z", CSVFormat.defaults().withHeader("A", "B", "C").build());
|
final CSVParser parser = new CSVParser("a,b,c\n1,2,3\nx,y,z", CSVFormat.newBuilder().withHeader("A", "B", "C").build());
|
||||||
final Map<String, Integer> headerMap = parser.getHeaderMap();
|
final Map<String, Integer> headerMap = parser.getHeaderMap();
|
||||||
final Iterator<String> columnNames = headerMap.keySet().iterator();
|
final Iterator<String> columnNames = headerMap.keySet().iterator();
|
||||||
// Headers are iterated in column order.
|
// Headers are iterated in column order.
|
||||||
|
@ -622,7 +622,7 @@ public class CSVParserTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetRecordWithMultiiLineValues() throws Exception {
|
public void testGetRecordWithMultiiLineValues() throws Exception {
|
||||||
final CSVParser parser = new CSVParser("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\"" + CRLF + "\"c\r\n1\",\"c\r\n2\"",
|
final CSVParser parser = new CSVParser("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\"" + CRLF + "\"c\r\n1\",\"c\r\n2\"",
|
||||||
CSVFormat.defaults().withRecordSeparator(CRLF).build());
|
CSVFormat.newBuilder().withRecordSeparator(CRLF).build());
|
||||||
CSVRecord record;
|
CSVRecord record;
|
||||||
assertEquals(0, parser.getRecordNumber());
|
assertEquals(0, parser.getRecordNumber());
|
||||||
assertEquals(0, parser.getLineNumber());
|
assertEquals(0, parser.getLineNumber());
|
||||||
|
@ -654,7 +654,7 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateRecordNumbers(String lineSeparator) throws IOException {
|
private void validateRecordNumbers(String lineSeparator) throws IOException {
|
||||||
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.defaults().withRecordSeparator(lineSeparator).build());
|
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.newBuilder().withRecordSeparator(lineSeparator).build());
|
||||||
CSVRecord record;
|
CSVRecord record;
|
||||||
assertEquals(0, parser.getRecordNumber());
|
assertEquals(0, parser.getRecordNumber());
|
||||||
assertNotNull(record = parser.nextRecord());
|
assertNotNull(record = parser.nextRecord());
|
||||||
|
@ -671,7 +671,7 @@ public class CSVParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateLineNumbers(String lineSeparator) throws IOException {
|
private void validateLineNumbers(String lineSeparator) throws IOException {
|
||||||
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.defaults().withRecordSeparator(lineSeparator).build());
|
final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator + "c", CSVFormat.newBuilder().withRecordSeparator(lineSeparator).build());
|
||||||
assertEquals(0, parser.getLineNumber());
|
assertEquals(0, parser.getLineNumber());
|
||||||
assertNotNull(parser.nextRecord());
|
assertNotNull(parser.nextRecord());
|
||||||
assertEquals(1, parser.getLineNumber());
|
assertEquals(1, parser.getLineNumber());
|
||||||
|
|
|
@ -220,7 +220,7 @@ public class CSVPrinterTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMultiLineComment() throws IOException {
|
public void testMultiLineComment() throws IOException {
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withCommentStart('#').build());
|
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withCommentStart('#').build());
|
||||||
printer.printComment("This is a comment\non multiple lines");
|
printer.printComment("This is a comment\non multiple lines");
|
||||||
|
|
||||||
assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator, sw.toString());
|
assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator, sw.toString());
|
||||||
|
@ -293,7 +293,7 @@ public class CSVPrinterTest {
|
||||||
@Test
|
@Test
|
||||||
public void testQuoteAll() throws IOException {
|
public void testQuoteAll() throws IOException {
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withQuotePolicy(Quote.ALL).build());
|
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.ALL).build());
|
||||||
printer.printRecord("a", "b\nc", "d");
|
printer.printRecord("a", "b\nc", "d");
|
||||||
assertEquals("\"a\",\"b\nc\",\"d\"" + recordSeparator, sw.toString());
|
assertEquals("\"a\",\"b\nc\",\"d\"" + recordSeparator, sw.toString());
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ public class CSVPrinterTest {
|
||||||
@Test
|
@Test
|
||||||
public void testQuoteNonNumeric() throws IOException {
|
public void testQuoteNonNumeric() throws IOException {
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withQuotePolicy(Quote.NON_NUMERIC).build());
|
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.NON_NUMERIC).build());
|
||||||
printer.printRecord("a", "b\nc", Integer.valueOf(1));
|
printer.printRecord("a", "b\nc", Integer.valueOf(1));
|
||||||
assertEquals("\"a\",\"b\nc\",1" + recordSeparator, sw.toString());
|
assertEquals("\"a\",\"b\nc\",1" + recordSeparator, sw.toString());
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ public class CSVPrinterTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSingleLineComment() throws IOException {
|
public void testSingleLineComment() throws IOException {
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withCommentStart('#').build());
|
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withCommentStart('#').build());
|
||||||
printer.printComment("This is a comment");
|
printer.printComment("This is a comment");
|
||||||
|
|
||||||
assertEquals("# This is a comment" + recordSeparator, sw.toString());
|
assertEquals("# This is a comment" + recordSeparator, sw.toString());
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class PerformanceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private long parse(final Reader in, boolean traverseColumns) throws IOException {
|
private long parse(final Reader in, boolean traverseColumns) throws IOException {
|
||||||
final CSVFormat format = CSVFormat.defaults().withIgnoreSurroundingSpaces(false).build();
|
final CSVFormat format = CSVFormat.newBuilder().withIgnoreSurroundingSpaces(false).build();
|
||||||
long recordCount = 0;
|
long recordCount = 0;
|
||||||
for (final CSVRecord record : format.parse(in)) {
|
for (final CSVRecord record : format.parse(in)) {
|
||||||
recordCount++;
|
recordCount++;
|
||||||
|
|
Loading…
Reference in New Issue