Browse Source

Merge pull request #2046 from JamesZBL/patch-1

下载图片添加连接和读取的超时设置
pull/2077/head
Jiaju Zhuang 3 years ago committed by GitHub
parent
commit
d17b24fbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java

8
src/main/java/com/alibaba/excel/converters/url/UrlImageConverter.java

@ -3,6 +3,7 @@ package com.alibaba.excel.converters.url;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import com.alibaba.excel.converters.Converter; import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration; import com.alibaba.excel.metadata.GlobalConfiguration;
@ -27,8 +28,11 @@ public class UrlImageConverter implements Converter<URL> {
GlobalConfiguration globalConfiguration) throws IOException { GlobalConfiguration globalConfiguration) throws IOException {
InputStream inputStream = null; InputStream inputStream = null;
try { try {
inputStream = value.openStream(); URLConnection conn = value.openConnection();
byte[] bytes = IoUtils.toByteArray(inputStream); conn.setConnectTimeout(1000);
conn.setReadTimeout(5000);
inputStream = con.getInputStream();
byte[] bytes = IoUtils.toByteArray(inputStream);
return new WriteCellData<>(bytes); return new WriteCellData<>(bytes);
} finally { } finally {
if (inputStream != null) { if (inputStream != null) {

Loading…
Cancel
Save