
com.qiniu.service.line.SplitLineParser 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.service.line;
import com.qiniu.service.interfaces.ILineParser;
import java.io.IOException;
import java.util.*;
public class SplitLineParser implements ILineParser {
private String separator;
private Map indexMap;
public SplitLineParser(String separator, Map indexMap) throws IOException {
if (indexMap == null || indexMap.size() == 0) throw new IOException("there are no indexMap be set.");
this.separator = separator;
this.indexMap = indexMap;
}
public Map getItemMap(String line) throws IOException {
String[] items = line.split(separator);
Map itemMap = new HashMap<>();
String mapKey;
for (int i = 0; i < items.length; i++) {
mapKey = indexMap.get(String.valueOf(i));
if (mapKey != null) {
if (items[i] == null) itemMap.put(mapKey, null);
else itemMap.put(mapKey, items[i]);
}
}
if (itemMap.size() < indexMap.size())
throw new IOException("no enough indexes in line. The parameter indexes may have incorrect order or name.");
return itemMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy