com.qiniu.convert.Converter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qsuits Show documentation
Show all versions of qsuits Show documentation
qiniu-suits is a efficient tools for qiniu api implemented by java8.
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();
}
}
}