public class CsvParser extends Object
CSV parser
The code come from https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/
Modifier and Type | Field and Description |
---|---|
static char |
DEFAULT_QUOTE |
static char |
DEFAULT_SEPARATOR |
Constructor and Description |
---|
CsvParser() |
Modifier and Type | Method and Description |
---|---|
static List<Map<String,String>> |
parse(List<String> lines)
Parse a list of lines into list of LinkedHashMap.
|
static <T> List<T> |
parse(List<String> lines,
Class<T> recordType)
Parse a list of lines into list of recordType specified.
|
static <T> List<T> |
parse(List<String> lines,
Class<T> recordType,
Map<String,String> headerMapping)
Parse a list of lines into list of recordType specified.
|
static List<Map<String,String>> |
parse(String headerLine,
List<String> lines)
Parse a list of lines into list of LinkedHashMap.
|
static <T> List<T> |
parse(String header,
List<String> lines,
Class<T> recordType)
Parse a list of lines into list of recordType specified.
|
static <T> List<T> |
parse(String header,
List<String> lines,
Class<T> recordType,
Map<String,String> headerMapping)
Parse a list of lines into list of recordType specified.
|
static Map<String,String> |
parseDataLine(String headerLine,
String dataLine) |
static <T> T |
parseDataLine(String header,
String dataLine,
Class<T> recordType) |
static <T> T |
parseDataLine(String header,
String line,
Class<T> recordType,
Map<String,String> headerMapping) |
static List<String> |
parseLine(String line) |
static List<String> |
parseLine(String line,
char separator,
char quote) |
static void |
register() |
public static final char DEFAULT_QUOTE
public static final char DEFAULT_SEPARATOR
public static void register()
public static List<Map<String,String>> parse(List<String> lines)
Parse a list of lines into list of LinkedHashMap.
Note the first line must be the header line
lines
- the csv linespublic static List<Map<String,String>> parse(String headerLine, List<String> lines)
Parse a list of lines into list of LinkedHashMap.
Note the line list must not contains header line
headerLine
- the header linelines
- the csv linespublic static <T> List<T> parse(List<String> lines, Class<T> recordType)
Parse a list of lines into list of recordType specified.
Note the first line must be the header line
lines
- the csv linesrecordType
- the record typepublic static <T> List<T> parse(String header, List<String> lines, Class<T> recordType)
Parse a list of lines into list of recordType specified.
Note the line list must not contains header line
header
- the header linelines
- the csv linesrecordType
- the record typepublic static <T> T parseDataLine(String header, String dataLine, Class<T> recordType)
public static <T> List<T> parse(List<String> lines, Class<T> recordType, Map<String,String> headerMapping)
Parse a list of lines into list of recordType specified.
Note the first line must be the header line
lines
- the csv linesrecordType
- the record typeheaderMapping
- the header mappingpublic static <T> List<T> parse(String header, List<String> lines, Class<T> recordType, Map<String,String> headerMapping)
Parse a list of lines into list of recordType specified.
Note the line list must not contains header line
header
- the header linelines
- the csv linesrecordType
- the record typeheaderMapping
- the header mappingpublic static <T> T parseDataLine(String header, String line, Class<T> recordType, Map<String,String> headerMapping)
Copyright © 2018–2019 OSGL (Open Source General Library). All rights reserved.