View Javadoc

    1   package sharin.csv.parser;
    2
    3   import java.io.Reader;
    4
    5   import sharin.util.IoUtils;
    6
    7   public class BasicCsvPushParser implements CsvPushParser {
    8
    9       private final char separator;
    10
    11      public BasicCsvPushParser() {
    12          this(',');
    13      }
    14
    15      public BasicCsvPushParser(char separator) {
    16          this.separator = separator;
    17      }
    18
    19      public String[][] parseAll(Reader reader) {
    20          BasicCsvHandler handler = new BasicCsvHandler();
    21          parse(reader, handler);
    22          return handler.getRecords();
    23      }
    24
    25      public void parse(Reader reader, CsvHandler handler) {
    26          BasicCsvAutomaton automaton = new BasicCsvAutomaton(handler, separator);
    27          int ch = 0;
    28
    29          while (ch != -1) {
    30              ch = IoUtils.read(reader);
    31              automaton.put(ch);
    32          }
    33      }
    34  }