java.lang.Object
de.siegmar.fastcsv.reader.IndexedCsvReader<T>
- Type Parameters:
T- the type of the CSV record.
- All Implemented Interfaces:
Closeable,AutoCloseable
CSV reader implementation for indexed based access.
If no prebuilt index passed in (via IndexedCsvReader.IndexedCsvReaderBuilder.index(CsvIndex)) the constructor will initiate
indexing the file.
This process is optimized on performance and low memory usage – no CSV data is stored in memory.
The current status can be monitored via IndexedCsvReader.IndexedCsvReaderBuilder.statusListener(StatusListener).
This class is thread-safe.
Example use:
try (IndexedCsvReader<CsvRecord> csv = IndexedCsvReader.builder().ofCsvRecord(file)) {
CsvIndex index = csv.getIndex();
int lastPage = index.getPageCount() - 1;
List<CsvRecord> csvRecords = csv.readPage(lastPage);
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThis builder is used to create configured instances ofIndexedCsvReader. -
Method Summary
-
Method Details
-
builder
Constructs aIndexedCsvReader.IndexedCsvReaderBuilderto configure and build instances of this class.- Returns:
- a new
IndexedCsvReader.IndexedCsvReaderBuilderinstance.
-
getIndex
Get the index used for accessing the CSV file. That index is either a freshly built index or the index that has been passed viaIndexedCsvReader.IndexedCsvReaderBuilder.index(CsvIndex).- Returns:
- the index that is used for accessing the CSV file.
-
readPage
Reads a page of records.- Parameters:
page- the page to read (0-based).- Returns:
- a page of records, never
null. - Throws:
IOException- if an I/O error occurs.IllegalArgumentException- ifpageis < 0IndexOutOfBoundsException- if the file does not contain the specified page
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
toString
-