2 Star 0 Fork 0

20155207wxc/besti-java-20155207wxc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Pages.java 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
lnaswxc 提交于 2017-06-01 14:37 . 实验五
package cc.openhome;
import java.net.URL;
import java.util.concurrent.*;
import java.io.*;
public class Pages {
private URL[] urls;
private String[] fileNames;
private Executor executor;
public Pages(URL[] urls, String[] fileNames, Executor executor) {
this.urls = urls;
this.fileNames = fileNames;
this.executor = executor;
}
public void download() {
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
String fileName = fileNames[i];
executor.execute(() -> {
try {
dump(url.openStream(), new FileOutputStream(fileName));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
}
}
private void dump(InputStream src, OutputStream dest) throws IOException {
try (InputStream input = src; OutputStream output = dest) {
byte[] data = new byte[1024];
int length;
while ((length = input.read(data)) != -1) {
output.write(data, 0, length);
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/lnaswxc/besti-java-20155207wxc.git
git@gitee.com:lnaswxc/besti-java-20155207wxc.git
lnaswxc
besti-java-20155207wxc
besti-java-20155207wxc
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385