com.orion.office.csv.writer.CsvLambdaWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of orion-office Show documentation
Show all versions of orion-office Show documentation
orion office (excel csv and more...)
package com.orion.office.csv.writer;
import com.orion.lang.utils.Objects1;
import com.orion.office.csv.core.CsvWriter;
import java.io.File;
import java.io.OutputStream;
import java.io.Writer;
import java.util.function.Function;
/**
* csv lambda 导出器
*
* @author Jiahang Li
* @version 1.0.0
* @since 2021/9/8 17:59
*/
public class CsvLambdaWriter extends BaseCsvWriter, T> {
public CsvLambdaWriter(String file) {
this(new CsvWriter(file));
}
public CsvLambdaWriter(File file) {
this(new CsvWriter(file));
}
public CsvLambdaWriter(OutputStream out) {
this(new CsvWriter(out));
}
public CsvLambdaWriter(Writer writer) {
this(new CsvWriter(writer));
}
public CsvLambdaWriter(CsvWriter writer) {
super(writer);
}
@Override
protected String[] parseRow(T row) {
String[] store = super.capacityStore();
// 设置值
for (int i = 0; i < store.length; i++) {
Function fun = mapping.get(i);
if (fun == null) {
continue;
}
Object v = fun.apply(row);
if (v != null) {
store[i] = Objects1.toString(v);
} else {
store[i] = Objects1.toString(defaultValue.get(fun));
}
}
return store;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy