org.swiftboot.sheet.imp.CsvImporter Maven / Gradle / Ivy
package org.swiftboot.sheet.imp;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.text.StringTokenizer;
import org.swiftboot.sheet.CsvCellInfo;
import org.swiftboot.sheet.meta.Position;
import org.swiftboot.sheet.meta.SheetMeta;
import org.swiftboot.util.IoUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
/**
* Importer for CSV data sheet.
*
* @author swiftech
*/
public class CsvImporter extends BaseImporter {
public CsvImporter(String fileType) {
super(fileType);
}
@Override
public Map importFromStream(InputStream templateFileStream, SheetMeta meta) throws IOException {
// read lines
List lines = IoUtils.readToStringList(templateFileStream);
Map ret = new HashMap<>();
meta.accept((metaItem, startPos, rowCount, columnCount) -> {
List> matrix = new ArrayList<>();
boolean foundTarget = false;
for (int i = 0; i < lines.size(); i++) {
String row;
if (isStaticWay(metaItem)
&& (i < startPos.getRow() || i >= (startPos.getRow() + rowCount))) {
continue; // skip for static way.
}
else {
if (startPos != null && i >= (startPos.getRow() + rowCount)) {
break;
}
row = lines.get(i); // retrieve to be detected for predicate way.
}
StringTokenizer valueTokenizer = StringTokenizer.getCSVInstance(row);
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy