// create the iterator private static CsvIterator create(StreamReader breader, bool headerRow, char separator) { try { if (!headerRow) { return(new CsvIterator(breader, separator, ImmutableList.of(), ImmutableMap.of(), 0)); } string line = breader.ReadLine(); int lineNumber = 1; while (!string.ReferenceEquals(line, null)) { ImmutableList <string> headers = CsvFile.parseLine(line, lineNumber, separator); if (!headers.Empty) { return(new CsvIterator(breader, separator, headers, CsvFile.buildSearchHeaders(headers), lineNumber)); } line = breader.ReadLine(); lineNumber++; } throw new System.ArgumentException("Could not read header row from empty CSV file"); } catch (Exception ex) { try { breader.Close(); } catch (IOException ex2) { ex.addSuppressed(ex2); } throw ex; } catch (IOException ex) { try { breader.Close(); } catch (IOException ex2) { ex.addSuppressed(ex2); } throw new UncheckedIOException(ex); } }
//------------------------------------------------------------------------- /// <summary> /// Checks whether there is another row in the CSV file. /// </summary> /// <returns> true if there is another row, false if not </returns> /// <exception cref="UncheckedIOException"> if an IO exception occurs </exception> /// <exception cref="IllegalArgumentException"> if the file cannot be parsed </exception> public override bool hasNext() { if (nextRow != null) { return(true); } else { string line = null; while (!string.ReferenceEquals((line = Unchecked.wrap(() => reader.ReadLine())), null)) { currentLineNumber++; ImmutableList <string> fields = CsvFile.parseLine(line, currentLineNumber, separator); if (!fields.Empty) { nextRow = new CsvRow(headers_Renamed, searchHeaders, currentLineNumber, fields); return(true); } } return(false); } }