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

com.qiniu.convert.Converter Maven / Gradle / Ivy

There is a newer version: 8.4.8
Show newest version
package com.qiniu.convert;

import com.qiniu.interfaces.ITypeConvert;
import com.qiniu.util.JsonUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public abstract class Converter implements ITypeConvert {

    private List errorList = new ArrayList<>();

    public abstract T convertToV(E line) throws IOException;

    @Override
    public List convertToVList(List lineList) {
        if (lineList == null) return new ArrayList<>();
        List mapList = new ArrayList<>(lineList.size());
        for (E line : lineList) {
            try {
                mapList.add(convertToV(line));
            } catch (Exception e) {
                if (line instanceof String) {
                    errorList.add(String.join("\t", String.valueOf(line), "convert error", e.getMessage()));
                } else {
                    errorList.add(String.join("\t", JsonUtils.toJson(line), "convert error", e.getMessage()));
                }
            }
        }
        return mapList;
    }

    @Override
    public int errorSize() {
        return errorList.size();
    }

    @Override
    public String errorLines() {
        try {
            return String.join("\n", errorList);
        } finally {
            errorList.clear();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy