All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.orion.office.csv.writer.CsvMapWriter Maven / Gradle / Ivy

There is a newer version: 1.0.9
Show newest version
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.Map;

/**
 * csv map 导出器
 *
 * @author Jiahang Li
 * @version 1.0.0
 * @since 2021/1/22 21:55
 */
public class CsvMapWriter extends BaseCsvWriter> {

    public CsvMapWriter(String file) {
        this(new CsvWriter(file));
    }

    public CsvMapWriter(File file) {
        this(new CsvWriter(file));
    }

    public CsvMapWriter(OutputStream out) {
        this(new CsvWriter(out));
    }

    public CsvMapWriter(Writer writer) {
        this(new CsvWriter(writer));
    }

    public CsvMapWriter(CsvWriter writer) {
        super(writer);
    }

    @Override
    protected String[] parseRow(Map row) {
        String[] store = super.capacityStore();
        // 设置值
        for (int i = 0; i < store.length; i++) {
            K k = mapping.get(i);
            if (k == null) {
                continue;
            }
            V v = row.get(k);
            if (v != null) {
                store[i] = Objects1.toString(v);
            } else {
                store[i] = Objects1.toString(defaultValue.get(k));
            }
        }
        return store;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy