I would like to process CSV file of such structure:
header1,header2
val1.1, val1.2
val2.1, val2.2
But only if the first line contains both header names - otherwise throw an exception.
My current implementations using Apache Common CSV is:
Reader reader = new InputStreamReader(new ByteArrayInputStream(file.getContent()));
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
.withHeader("header1", "header2")
.withSkipHeaderRecord());
for (CSVRecord csvRecord : csvParser) { /* records processing */ }
The problem is that the first line might have values different than header names and the file is still processed.