@@ -53,19 +53,17 @@ 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 }
65- }
66- InputStream inputStream = null ;
67- try {
68- inputStream = InputStreamResponseHandler .INSTANCE .handleResponse (response );
66+ InputStream inputStream = InputStreamResponseHandler .INSTANCE .handleResponse (response );
6967
7068 // 视频文件不支持下载
7169 String fileName = getFileName (response );
@@ -75,11 +73,9 @@ public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String u
7573 String [] name_ext = fileName .split ("\\ ." );
7674 File localFile = FileUtils .createTmpFile (inputStream , name_ext [0 ], name_ext [1 ], tmpDirFile );
7775 return localFile ;
78- } finally {
79- if (inputStream != null ) {
80- inputStream .close ();
81- }
76+
8277 }
78+
8379 }
8480
8581 protected String getFileName (CloseableHttpResponse response ) {
0 commit comments