package MultiHandling;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import Downloadandsave.DownloadURLFile;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
public class MultiThread implements Runnable {
private static BufferedReader br = null;
private List<String> list;
private String paperdir = "";
String myDomain = "/paper/";
static {
try {
br = new BufferedReader(new FileReader("report.txt"), 10);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void run() {
String line = null;
while (true) {
this.list = new ArrayList<String>();
synchronized (br) {
try {
while ((line = br.readLine()) != null) {
paperdir = line.substring(line.indexOf("/paper/") + "/paper/".length(), line.length());
System.out.println("===============准备开始下载 " + paperdir + " 的全文及相关资源 ================");
prepareDownFiles(line);
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
Thread.sleep(3000);
downFiles(this.list);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (line == null)
break;
}
}
public void downFiles(List<String> list) throws InterruptedException {
for (String str : list) {
System.out.println("===============正在下载 " + str + " ================");
DownloadURLFile a = new DownloadURLFile();
a.downloadFromUrl(str, "Test" + File.separator + paperdir);
}
}
public void prepareDownFiles(String line) {
try {
URL url = new URL(line);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
InputStream is = null;
is = url.openStream();
BufferedReader bReader = new BufferedReader(new InputStreamReader(is));
String rLine = null;
String tmp_rLine = null;
while ((rLine = bReader.readLine()) != null) {
tmp_rLine = rLine;
int str_len = tmp_rLine.length();
if (str_len > 0) {
String regUrl = "(?<=(href=)[\"]?[\']?)[^\\s\"\'\\?]*(" + myDomain + ")[^\\s\"\'>]*";
Pattern p = Pattern.compile(regUrl, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(tmp_rLine);
boolean blnp = m.find();
while (blnp == true) {
list.add("https://papers.nips.cc" + m.group(0));
tmp_rLine = tmp_rLine.substring(m.end(), tmp_rLine.length());
m = p.matcher(tmp_rLine);
blnp = m.find();
}
}
tmp_rLine = null;
}
is.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

wuxinxing1981
- 粉丝: 3
最新资源
- 右岸地下厂房进水口1310m以上开挖支护技术方案-secret.doc
- [成都]高层现代风格办公综合体建筑设计方案(含住宅、商业建筑).pdf
- 2号栋北钢筋混凝土挡土墙施工方案.doc
- 业务外驻管理规定(最新版2009-2-18).doc
- 球罐组装几何尺寸报告.doc
- 北京某小区工程测量施工方案.doc
- 3.29项目成员工作周报.doc
- 财务管理-01.ppt
- 家庭教育指导工作计划.doc
- [北京]高层办公楼防水工程施工工艺.doc
- 简洁实用的目标检测操作界面平台
- 注册公用设备工程师(暖通)考试模拟题及答案(三).doc
- 基于计算机网络技术的医院信息化建设发展.docx
- 《建筑结构抗震设计》课后习题全解(王社良版).doc
- 定期考绩汇总表.doc
- 成都某超高层工程临时用水方案.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


