-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#724 - parse csv to rows and columns
- Loading branch information
1 parent
2f4ccab
commit 6546f4c
Showing
5 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...terServer/src/main/java/de/deadlocker8/budgetmaster/transactions/csvImport/CsvParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package de.deadlocker8.budgetmaster.transactions.csvImport; | ||
|
||
import com.opencsv.CSVParser; | ||
import com.opencsv.CSVParserBuilder; | ||
import com.opencsv.CSVReader; | ||
import com.opencsv.CSVReaderBuilder; | ||
import com.opencsv.exceptions.CsvValidationException; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CsvParser | ||
{ | ||
public static List<CsvRow> parseCsv(String csvString, char separator) throws IOException, CsvValidationException | ||
{ | ||
final ArrayList<CsvRow> csvRows = new ArrayList<>(); | ||
|
||
final CSVParser csvParser = new CSVParserBuilder().withSeparator(separator).build(); | ||
|
||
try(CSVReader reader = new CSVReaderBuilder( | ||
new StringReader(csvString)) | ||
.withCSVParser(csvParser) | ||
.build()) | ||
{ | ||
String[] columns; | ||
while((columns = reader.readNext()) != null) | ||
{ | ||
csvRows.add(new CsvRow(columns)); | ||
} | ||
} | ||
|
||
return csvRows; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
BudgetMasterServer/src/main/resources/languages/base_de.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
BudgetMasterServer/src/main/resources/languages/base_en.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters