/// <summary> /// Construct a BaseTabularReader to read the given stream. /// </summary> /// <param name="stream">Stream to read</param> /// <param name="hasHeaderRow">True to read the first row as column names, False not to pre-read anything</param> public BaseTabularReader(Stream stream, bool hasHeaderRow = true) { _reader = new BufferedRowReader(stream, SplitRows); _columnHeadingsList = new List <string>(); _columnHeadings = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); _cellPositionArray = new PartialArray <int>(1024, false); // Read the heading row and record heading positions if (hasHeaderRow) { if (!NextRow()) { throw new IOException("Reader didn't find any rows when trying to read a header row."); } for (int i = 0; i < _currentRowColumns.Count; ++i) { string columnName = this.Current(i).ToString(); _columnHeadingsList.Add(columnName); _columnHeadings[columnName] = i; } // Header row doesn't count toward row count read RowCountRead = 0; } }
public void Dispose() { if (_reader != null) { _reader.Dispose(); _reader = null; } }
private void ReadColumns(Stream stream) { // Make a reader to split the input on newlines BufferedRowReader reader = new BufferedRowReader(stream, (block, array) => block.Split(UTF8.Newline, array)); // Scan the lines for column names (something before a colon) while (true) { String8 line = reader.NextRow(); if (line.IsEmpty()) { break; } ReadColumnLine(line); } // Reset the stream for the second read stream.Seek(0, SeekOrigin.Begin); }
public LdfTabularReader(Stream stream) { _reader = new BufferedRowReader(stream, SplitRows); _columnNamesBlock = new String8Block(); _columnIndices8 = new Dictionary <String8, int>(); _columnIndices = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); _columnNames = new List <string>(); _currentRowBlock = new String8Block(); _lineArray = new PartialArray <int>(1024, false); ReadColumns(stream); _currentRowValues = new String8TabularValue[_columnNames.Count]; for (int i = 0; i < _currentRowValues.Length; ++i) { _currentRowValues[i] = new String8TabularValue(); } }