Package de.espirit.common.util
Class CsvReader
java.lang.Object
de.espirit.common.util.CsvReader
Utility class to parse CSV files.
Usage:final CsvReader csvReader = new CsvReader(reader, ';'); CsvReader.CsvToken token = csvReader.read(); while (token.getType() != CsvReader.CsvToken.EOF) { if (token.getType() == CsvReader.CsvToken.NEW_LINE) { // handle newline } else { // handle value final String value = token.getValue(); } token = csvReader.read(); }
- Since:
- 5.1.28
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Class representing a single token -
Constructor Summary
ConstructorDescriptionConstructs a new CsvReader with the given reader as source of the csv file with default delimiter ';'.Constructs a new CsvReader with the given reader as source of the csv file and the given char as delimiter of the csv file -
Method Summary
Modifier and TypeMethodDescriptionparseCsvToList
(@NotNull Reader reader, char delim) parses the csv source of the given reader to a list of lists ofString
'sstatic @NotNull String[][]
parseCsvToStringArray
(@NotNull Reader reader, char delim) parses the csv source of the given reader to a StringArray of StringArrays@NotNull CsvReader.CsvToken
read()
Returns aCsvToken
of the typeCsvReader.CsvToken.VALUE
orCsvReader.CsvToken.NEW_LINE
orCsvReader.CsvToken.EOF
-
Constructor Details
-
CsvReader
Constructs a new CsvReader with the given reader as source of the csv file and the given char as delimiter of the csv file- Parameters:
reader
- reader for the csv filedelim
- the delimiter char of the csv file- Since:
- 5.1.28
-
CsvReader
Constructs a new CsvReader with the given reader as source of the csv file with default delimiter ';'.- Parameters:
reader
- reader for the csv file- Since:
- 5.1.28
-
-
Method Details
-
read
Returns aCsvToken
of the typeCsvReader.CsvToken.VALUE
orCsvReader.CsvToken.NEW_LINE
orCsvReader.CsvToken.EOF
- Returns:
- CsvToken - currentToken
- Throws:
IOException
- from underlying stream- Since:
- 5.1.28
- See Also:
-
parseCsvToList
@NotNull public static @NotNull List<List<String>> parseCsvToList(@NotNull @NotNull Reader reader, char delim) throws IllegalStateException parses the csv source of the given reader to a list of lists ofString
's- Parameters:
reader
- the reader for the csv filedelim
- the delimiter char of the csv file- Returns:
- List - a List of Lists
- Throws:
IllegalStateException
- if the csv file is invalid, or if aIOException
is encountered while reading- Since:
- 5.1.28
-
parseCsvToStringArray
@NotNull public static @NotNull String[][] parseCsvToStringArray(@NotNull @NotNull Reader reader, char delim) throws IllegalStateException parses the csv source of the given reader to a StringArray of StringArrays- Parameters:
reader
- the reader for the csv filedelim
- the delimiter char of the csv file- Returns:
- String[][] - a StringArray of StringArrays
- Throws:
IllegalStateException
- if the csv file is invalid, or if aIOException
is encountered while reading- Since:
- 5.1.28
-