com.github.hackerwin7.jlib.utils.executors.DBAIpCompare Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jlib-utils Show documentation
Show all versions of jlib-utils Show documentation
utils set for java projects
package com.github.hackerwin7.jlib.utils.executors;
import com.github.hackerwin7.jlib.utils.drivers.file.FileUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by fff on 12/21/15.
*/
public class DBAIpCompare {
public static void main(String[] args) throws Exception {
DBAIpCompare dba = new DBAIpCompare();
dba.mainProc();
//dba.distinct();
}
public void mainProc() throws Exception {
Set ips = loadIpList("ip.list");
Set ipd = loadIpList("ip_dba.list");
Set res = new HashSet<>();
res.addAll(ips);
res.retainAll(ipd);
for(String ip : res) {
System.out.println(ip);
}
}
private Set loadIpList(String fileName) throws Exception {
InputStream is = TrainBdpConfig.class.getClassLoader().getResourceAsStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
Set jobs = new HashSet<>();
while ((line = br.readLine()) != null) {
if(!StringUtils.isBlank(line)) {
jobs.add(line);
}
}
br.close();
is.close();
return jobs;
}
public void distinct() throws Exception {
List ips = FileUtils.file2List("ip.list");
Set desIps = new HashSet<>();
for(String ip : ips) {
desIps.add(ip);
}
for(String ip : desIps) {
System.out.println(ip);
}
}
}