3030import java .util .zip .GZIPInputStream ;
3131
3232import org .apache .commons .csv .CSVFormat ;
33+ import org .apache .commons .csv .CSVRecord ;
3334import org .apache .commons .io .IOUtils ;
3435import org .junit .BeforeClass ;
3536import org .junit .Ignore ;
@@ -64,13 +65,18 @@ private BufferedReader getBufferedReader() throws IOException {
6465 return new BufferedReader (new FileReader (BIG_FILE ));
6566 }
6667
67- private long parse (final Reader in ) throws IOException {
68+ private long parse (final Reader in , boolean traverseColumns ) throws IOException {
6869 final CSVFormat format = CSVFormat .DEFAULT .withIgnoreSurroundingSpaces (false );
69- long count = 0 ;
70- for (final Object record : format .parse (in )) {
71- count ++;
70+ long recordCount = 0 ;
71+ for (final CSVRecord record : format .parse (in )) {
72+ recordCount ++;
73+ if (traverseColumns ) {
74+ for (String value : record ) {
75+ // do nothing for now
76+ }
77+ }
7278 }
73- return count ;
79+ return recordCount ;
7480 }
7581
7682 private void println () {
@@ -89,9 +95,9 @@ private long readAll(final BufferedReader in) throws IOException {
8995 return count ;
9096 }
9197
92- public long testParseBigFile () throws Exception {
98+ public long testParseBigFile (boolean traverseColumns ) throws Exception {
9399 final long startMillis = System .currentTimeMillis ();
94- final long count = this .parse (this .getBufferedReader ());
100+ final long count = this .parse (this .getBufferedReader (), traverseColumns );
95101 final long totalMillis = System .currentTimeMillis () - startMillis ;
96102 this .println (String .format ("File parsed in %,d milliseconds with Commons CSV: %,d lines." , totalMillis , count ));
97103 return totalMillis ;
@@ -101,7 +107,7 @@ public long testParseBigFile() throws Exception {
101107 public void testParseBigFileRepeat () throws Exception {
102108 long bestTime = Long .MAX_VALUE ;
103109 for (int i = 0 ; i < this .max ; i ++) {
104- bestTime = Math .min (this .testParseBigFile (), bestTime );
110+ bestTime = Math .min (this .testParseBigFile (false ), bestTime );
105111 }
106112 this .println (String .format ("Best time out of %,d is %,d milliseconds." , this .max , bestTime ));
107113 }
0 commit comments