package com.nokia.domainb.util;

import org.springframework.util.ResourceUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;

public class Utils {
    /**
     * 读取手机号放入set去重
     */
    public static Set<String> readPhones() {
        Set<String> result = new HashSet<>();
//        String location = "classpath:data/7月1-24日移网质量投诉业务号码.txt";
//        String location = "classpath:data/10.txt";
//        String location = "classpath:data/100.txt";
//        String location = "classpath:data/1000.txt";
//        String location = "classpath:data/2000.txt";
//        String location = "classpath:data/5000.txt";
        String location = "classpath:data/8000.txt";
//        String location = "classpath:data/10000.txt";
//        String location = "classpath:data/10000+.txt";
//        String location = "classpath:data/测试号码2.txt";
//        String location = "classpath:data/测试号码1万多.txt";
        FileInputStream fis;
        try {
            File file = ResourceUtils.getFile(location);
            fis = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return result;
        }
        InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        while (true) {
            try {
                if ((line = br.readLine()) == null) {
                    break;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            result.add(line);
        }
        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}
