View Javadoc

    1   package sharin.csv.parser;
    2
    3   import java.io.Reader;
    4   import java.util.ArrayList;
    5   import java.util.Iterator;
    6   import java.util.List;
    7
    8   public class BasicCsvPullParser implements CsvPullParser {
    9
    10      private final char separator;
    11
    12      public BasicCsvPullParser() {
    13          this(',');
    14      }
    15
    16      public BasicCsvPullParser(char separator) {
    17          this.separator = separator;
    18      }
    19
    20      public String[][] parseAll(Reader reader) {
    21          List<String[]> recordList = new ArrayList<String[]>();
    22
    23          for (String[] record : parse(reader)) {
    24              recordList.add(record);
    25          }
    26
    27          return recordList.toArray(new String[recordList.size()][]);
    28      }
    29
    30      public Iterable<String[]> parse(final Reader reader) {
    31          return new Iterable<String[]>() {
    32
    33              public Iterator<String[]> iterator() {
    34                  return new BasicCsvIterator(reader, separator);
    35              }
    36          };
    37      }
    38  }