
com.qiniu.convert.LineToMap 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.util.FileNameUtils;
import com.qiniu.util.LineUtils;
import java.io.IOException;
import java.util.*;
public class LineToMap extends Converter> {
public LineToMap(String parseType, String separator, String rmKeyPrefix, Map indexMap) throws IOException {
if ("json".equals(parseType)) {
this.lineParser = line -> process(rmKeyPrefix, LineUtils.getItemMap(line, indexMap, false));
} else if ("csv".equals(parseType)) {
this.lineParser = line -> process(rmKeyPrefix, LineUtils.getItemMap(line, ",", indexMap, false));
} else if ("tab".equals(parseType)) {
this.lineParser = line -> process(rmKeyPrefix, LineUtils.getItemMap(line, separator, indexMap, false));
} else {
throw new IOException("please check your format for line to map.");
}
}
private Map process(String rmKeyPrefix, Map itemMap) {
String key = itemMap.get("key") != null ? FileNameUtils.rmPrefix(rmKeyPrefix, itemMap.get("key")) : null;
itemMap.put("key", key);
return itemMap;
}
@Override
public Map convertToV(String line) throws IOException {
return lineParser.getItemMap(line);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy