Class CSVReaderHeaderAware
java.lang.Object
com.opencsv.CSVReader
com.opencsv.CSVReaderHeaderAware
- All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<String[]>
Handy reader when there's insufficient motivation to use the bean binding but
the header mapping is still desired.
- Since:
- 4.2
- Author:
- Andre Rosot
-
Field Summary
Fields inherited from class CSVReader
br, DEFAULT_KEEP_CR, DEFAULT_MULTILINE_LIMIT, DEFAULT_SKIP_LINES, DEFAULT_VERIFY_READER, errorLocale, hasNext, keepCR, lineReader, linesRead, linesSkipped, multilineLimit, parser, PASSTHROUGH_EXCEPTIONS, peekedLine, peekedLines, READ_AHEAD_LIMIT, recordsRead, skipLines, verifyReader -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class CSVReader
close, combineResultsFromMultipleReads, getLinesRead, getMultilineLimit, getNextLine, getParser, getRecordsRead, getSkipLines, isClosed, iterator, keepCarriageReturns, peek, readAll, readNext, readNextSilently, setErrorLocale, skip, validateResult, verifyReaderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
CSVReaderHeaderAware
Constructor with supplied reader.- Parameters:
reader- The reader to an underlying CSV source- Throws:
IOException- If there is an error when reading the header
-
-
Method Details
-
readNext
Retrieves a specific data element from a line based on the value of the header.- Parameters:
headerNames- Name of the header element whose data we are trying to find- Returns:
- The data element whose position matches that of the header whose value is passed in. Will return null when there are no more data elements.
- Throws:
IOException- An error occured during the read or there is a mismatch in the number of data items in a row and the number of header itemsIllegalArgumentException- If headerName does not existCsvValidationException- If a custom defined validator fails.
-
readMap
Reads the next line and returns a map of header values and data values.- Returns:
- A map whose key is the header row of the data file and the values is the data values. Or null if the line is blank.
- Throws:
IOException- An error occurred during the read or there is a mismatch in the number of data items in a row and the number of header items.CsvValidationException- If a custom defined validator fails.
-