com.utils.HttpUtil.downloadData(url, f);
com.utils.IOUtil.unzip(f, f.replace(".gz", ""));
File file_to_read = new File(f.replaceAll(".gz", ""));
BigFile lines = null;
try {
lines = new BigFile(file_to_read.toString());
} catch (Exception e) {
fatal("Excpetion", e);
return;
}
try {
Statement stat = conn_url.createStatement();
stat.executeUpdate(properties.get("query_delete"));
stat.close();
} catch (SQLException e) {
fatal("SQLException", e);
}
try {
conn_url.setAutoCommit(false);
} catch (SQLException e) {
fatal("SQLException", e);
}
boolean ok = true;
int i = 0;
for (String line : lines) {
if (StringUtil.isEmpty(line) || line.indexOf(" ") == -1) {
continue;
}
//eseguo la insert
try {
line = line.substring(line.indexOf(" "));
line = line.trim();
if (getIPException(line)) {
continue;
}
Statement stat = this.conn_url.createStatement();
stat.executeUpdate("insert into blacklist(url) values('" + line + "')");
stat.close();
i++;
} catch (SQLException e) {
fatal("SQLException", e);
try {
conn_url.rollback();
} catch (SQLException ex) {
fatal("SQLException", ex);
}
ok = false;
break;
}
}
//elimino il file originale per risparmiare spazio su disco
boolean del = file_to_read.delete();
debug("File " + file_to_read + " del:" + del);
//altro file da scaricare...
//scarico il file
name = "spam-ip.com_" + DateTimeUtil.getNowWithFormat("MM-dd-yyyy") + ".csv";
f = this.path_app_root + "/" + this.properties.get("dir") + "/";
org.apache.commons.io.FileUtils.forceMkdir(new File(f));
f += "/" + name;
url = "http://spam-ip.com/csv_dump/" + name;
debug("(2) - start download: " + url);
com.utils.HttpUtil.downloadData(url, f);
file_to_read = new File(f);
try {
lines = new BigFile(file_to_read.toString());
} catch (Exception e) {
fatal("Exception", e);
return;
}