Jagger
 All Classes Namespaces Files Functions Variables Groups Pages
Iterator<T> com.griddynamics.jagger.providers.CsvProvider< T >.iterator ( )

Returns iterator over created objects.

Author
Nikolay Musienko
Details:

Reads data from file, translates it to java objects, return iterator over this objects

125  {
126 
127  return new AbstractIterator<T>() {
128 
129  private CSVParser parser;
130 
131  {
132  init();
133  }
134 
135  private void init(){
136  if (path == null) {
137  throw new TechnicalException("File path can't be NULL!");
138  }
139  try {
140  parser = new CSVParser(new BufferedReader(new FileReader(new File(path))), strategy);
141  } catch (FileNotFoundException e) {
142  throw Throwables.propagate(e);
143  } if(readHeader) {
144  try {
145  objectCreator.setHeader(parser.getLine());
146  } catch (IOException e){
147  throw Throwables.propagate(e);
148  }
149  }
150 
151  }
152 
153  @Override
154  protected T computeNext() {
155  try {
156  String[] strings = parser.getLine();
157  if(strings == null) {
158  return endOfData();
159  }
160  return objectCreator.createObject(strings);
161  } catch (IOException e) {
162  throw Throwables.propagate(e);
163  }
164  }
165 
166  };
167  }