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

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

There is a newer version: 8.4.8
Show newest version
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 ObjectToMap {

    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;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy