title: how to fetch and validate csv header in open csv?
body: <p>I want to fetch header from csv file . If I am not use this skipLines then I will get header at 0 index array . But I want to fetch header directly using HeaderColumnNameMappingStrategy but it will not work with my code.</p>
  
  <p>I also want to validate header column list ( like csv had not allowed to contain extra column)</p>
  
  <p>I had also check this <a href="https://stackoverflow.com/questions/35594121/how-to-validate-the-csv-headers-using-opencsv">How to validate the csv headers using opencsv</a> but it was not helpful to me.</p>
  
  <pre><code>@SuppressWarnings({ "unchecked", "rawtypes" })
  public Map&lt;String, Object&gt; handleStockFileUpload(MultipartFile file, Long customerId) {
      Map&lt;String, Object&gt; responseMap = new HashMap&lt;&gt;();
      responseMap.put("datamap", "");
      responseMap.put("errormap", "");
      responseMap.put("errorkeys", "");
  
      List&lt;Map&lt;String, Integer&gt;&gt; list = new ArrayList&lt;&gt;();
      List&lt;StockCsvDTO&gt; csvStockList = new ArrayList&lt;&gt;();
  
      try {
          String fileName = new SimpleDateFormat("yyyy_MM_dd_HHmmss").format(new Date()) + "_" + file.getOriginalFilename();
          responseMap.put("filename", fileName);
  
          File stockFile = new File(productsUploadFilePath + fileName);
          stockFile.getParentFile().mkdirs();
          FileOutputStream fos = new FileOutputStream(stockFile);
          fos.write(file.getBytes());
          fos.close();
  
  
          CsvTransfer csvTransfer = new CsvTransfer();
  
  
          ColumnPositionMappingStrategy ms = new ColumnPositionMappingStrategy();
          ms.setType(StockCsv.class);
  
          Reader reader = Files.newBufferedReader(Paths.get(productsUploadFilePath + fileName));
          CSVReader csvReader =  new CSVReader(reader);
  
          CsvToBean cb = new CsvToBeanBuilder(reader)
            .withType(StockCsv.class)
            .withMappingStrategy(ms)
            .withSkipLines(1)
            .build();
  
         csvTransfer.setCsvList(cb.parse());
         reader.close();
  
  
         csvStockList = csvTransfer.getCsvList();
  
      } catch (Exception e) {
          e.printStackTrace();
          responseMap.put("status", "servererror");
      }
  
       responseMap.put("datamap", csvStockList);
  
      return responseMap;
  }
  </code></pre>