Class CsvUtils

java.lang.Object
org.lfenergy.compas.sct.commons.util.CsvUtils

public final class CsvUtils extends Object
Utility class to parse CSV files. This utility class intention is to normalize all CSV inputs in the project: - Separator is SEPARATOR. - Lines starting with COMMENT_PREFIX will be ignored. Allow to write copyright and headers at the beginning of the file for example. - blank lines are ignored
  • Method Details

    • parseRows

      public static <T> List<T> parseRows(String resourcePath, Charset charset, Class<T> targetClass)
      Read CSV from a resource
      Parameters:
      resourcePath - path of the resource
      charset - charset of the resource
      targetClass - Each row will be mapped to this class.
      Returns:
      list of rows, mapped as targetClass
    • parseRows

      public static <T> List<T> parseRows(Reader csvSource, Class<T> targetClass)
      Read CSV from a Reader. Reader will be automatically closed when the method returns or throw an exception.
      Parameters:
      csvSource - CSV input
      targetClass - Each row will be mapped to this class.
      Returns:
      list of rows, mapped as targetClass