// 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); } }