@@ -53,26 +53,29 @@ public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String u
5353 httpGet .setConfig (config );
5454 }
5555
56- CloseableHttpResponse response = httpclient .execute (httpGet );
56+ try ( CloseableHttpResponse response = httpclient .execute (httpGet )) {
5757
58- Header [] contentTypeHeader = response .getHeaders ("Content-Type" );
59- if (contentTypeHeader != null && contentTypeHeader .length > 0 ) {
60- // 下载媒体文件出错
61- if (ContentType .TEXT_PLAIN .getMimeType ().equals (contentTypeHeader [0 ].getValue ())) {
62- String responseContent = Utf8ResponseHandler .INSTANCE .handleResponse (response );
63- throw new WxErrorException (WxError .fromJson (responseContent ));
58+ Header [] contentTypeHeader = response .getHeaders ("Content-Type" );
59+ if (contentTypeHeader != null && contentTypeHeader .length > 0 ) {
60+ // 下载媒体文件出错
61+ if (ContentType .TEXT_PLAIN .getMimeType ().equals (contentTypeHeader [0 ].getValue ())) {
62+ String responseContent = Utf8ResponseHandler .INSTANCE .handleResponse (response );
63+ throw new WxErrorException (WxError .fromJson (responseContent ));
64+ }
6465 }
66+ InputStream inputStream = InputStreamResponseHandler .INSTANCE .handleResponse (response );
67+
68+ // 视频文件不支持下载
69+ String fileName = getFileName (response );
70+ if (StringUtils .isBlank (fileName )) {
71+ return null ;
72+ }
73+ String [] name_ext = fileName .split ("\\ ." );
74+ File localFile = FileUtils .createTmpFile (inputStream , name_ext [0 ], name_ext [1 ], tmpDirFile );
75+ return localFile ;
76+
6577 }
66- InputStream inputStream = InputStreamResponseHandler .INSTANCE .handleResponse (response );
67-
68- // 视频文件不支持下载
69- String fileName = getFileName (response );
70- if (StringUtils .isBlank (fileName )) {
71- return null ;
72- }
73- String [] name_ext = fileName .split ("\\ ." );
74- File localFile = FileUtils .createTmpFile (inputStream , name_ext [0 ], name_ext [1 ], tmpDirFile );
75- return localFile ;
78+
7679 }
7780
7881 protected String getFileName (CloseableHttpResponse response ) {
0 commit comments