-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#228] Streamlined processing of xls and csv files using adapter pattern
- Loading branch information
Evgenii Grigorev
committed
Dec 15, 2024
1 parent
d5b03b5
commit 125d65e
Showing
4 changed files
with
199 additions
and
222 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
53 changes: 53 additions & 0 deletions
53
...odules/module-tabular/src/main/java/cz/cvut/spipes/modules/util/CSVFileReaderAdapter.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,53 @@ | ||
package cz.cvut.spipes.modules.util; | ||
|
||
import cz.cvut.spipes.modules.ResourceFormat; | ||
import cz.cvut.spipes.modules.model.Region; | ||
import org.supercsv.io.CsvListReader; | ||
import org.supercsv.io.ICsvListReader; | ||
import org.supercsv.prefs.CsvPreference; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class CSVFileReaderAdapter implements FileReaderAdapter { | ||
private ICsvListReader listReader; | ||
private CsvPreference csvPreference; | ||
|
||
public CSVFileReaderAdapter(CsvPreference csvPreference) { | ||
this.csvPreference = csvPreference; | ||
} | ||
|
||
@Override | ||
public void initialise(InputStream inputStream, ResourceFormat sourceResourceFormat, int tableIndex) throws IOException { | ||
listReader = new CsvListReader(new InputStreamReader(inputStream), csvPreference); | ||
} | ||
|
||
@Override | ||
public String[] getHeader() throws IOException { | ||
return listReader.getHeader(true); | ||
} | ||
|
||
@Override | ||
public boolean hasNext() throws IOException { | ||
return listReader.read() != null; | ||
} | ||
|
||
@Override | ||
public List<String> getNextRow() throws IOException { | ||
return listReader.read(); | ||
} | ||
|
||
@Override | ||
public List<Region> getMergedRegions() { | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public String getLabel(){ | ||
return null; | ||
} | ||
} |
Oops, something went wrong.