提交 d70f666b authored 作者: 张航's avatar 张航

修改了工具类信息以及主函数日志打印

上级 a39ec305
......@@ -151,6 +151,11 @@ public class DownMap implements ApplicationRunner {
}
/**
* @description: 下载地图的Callable,该类用于异步多线程下载地图
* @author: zhanghang
* @date: 2020/4/7
**/
class DownMapCallable implements Callable<String> {
private int z;
......@@ -178,7 +183,7 @@ public class DownMap implements ApplicationRunner {
}
return imgUrl + " Loaded";
} catch (Exception e) {
//log.error(imgUrl + " Down Failed");
e.printStackTrace();
errResults.add("Failed: " + imgUrl + " ErrorMsg >> " + e.getMessage());
return imgUrl + " Down Failed";
}
......
......@@ -180,7 +180,7 @@ public class HttpClientConfig {
setConnectionRequestTimeout(connectionRequestTimeout).
setSocketTimeout(socketTimeout);
setSocketTimeout(socketTimeout).setRedirectsEnabled(true);
}
......
......@@ -3,6 +3,7 @@ package com.comleader.ldmapdownload.util;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
......@@ -11,9 +12,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.sql.SQLOutput;
/**
......@@ -63,6 +62,8 @@ public class HttpUtil {
ins = response.getEntity().getContent();
// 写入图片
FileUtil.writeFromStream(ins, file);
}else {
response.getEntity();
}
} finally {
// 释放资源
......@@ -76,4 +77,36 @@ public class HttpUtil {
}
public static void writeFromStream(InputStream is, File file) {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
// 下载图片到本地存储
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(new FileOutputStream(file));
byte[] buffer = new byte[1024];
int len = -1;
//while ((len = bis.read(buffer)) != -1) {
while ((len = bis.read(buffer)) > 0) {
bos.write(buffer, 0, len);
bos.flush();
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
// 释放资源
if (bos != null){
bos.close();
}
if (bis != null){
bis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
......@@ -18,17 +18,17 @@ map.baseurl=http://webrd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1scale=1&s
map.type=CUSTOM
# 下载地图的层级 7 - 18
map.minLv=17
map.maxLv=17
map.minLv=14
map.maxLv=14
# 线程数
map.threadNum=1000
map.threadNum=2000
# 是否下载前6级(不能与其余的同时进行)
map.Lv6.flag=false
# 是否继续下载
map.download.append=true
map.download.append=false
# 这个注释用来备注下下载地图的经纬度
# left: 113.587,34.694 right: 113.801,34.799
\ No newline at end of file
#最大连接数
http.maxTotal=1000
http.maxTotal=2000
#并发数
http.defaultMaxPerRoute=50
http.defaultMaxPerRoute=60
#创建连接的最长时间
http.connectTimeout=60000
#从连接池中获取到连接的最长时间
http.connectionRequestTimeout=60000
http.connectionRequestTimeout=6000000
#数据传输的最长时间
http.socketTimeout=60000
http.socketTimeout=120000
#提交请求前测试连接是否可用
http.staleConnectionCheckEnabled=true
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论