@@ -54,7 +54,7 @@ private Downloader() {
5454 this .idleConnectionMonitor .start ();
5555 }
5656
57- public HeadAttr headFile (String url , boolean qiniuDownLoadFlag ) {
57+ public HeadAttr headFile (String url , boolean qiniuDownLoadFlag ) throws Exception {
5858
5959 int retry = 0 ;
6060 int maxRetryCount = 5 ;
@@ -95,8 +95,16 @@ public HeadAttr headFile(String url, boolean qiniuDownLoadFlag) {
9595 httpHead .setHeader ("Connection" , "Keep-Alive" );
9696 httpHead .setHeader ("User-Agent" , "cos-migrate-tool" );
9797
98+ HttpResponse httpResponse = null ;
9899 try {
99- HttpResponse httpResponse = httpClient .execute (httpHead );
100+ httpResponse = httpClient .execute (httpHead );
101+ } catch (Exception e ) {
102+ log .error ("head file attr fail, url: {}, retry: {}/{}, exception: {}" , url , retry ,
103+ maxRetryCount , e .toString ());
104+ httpHead .abort ();
105+ ++retry ;
106+ }
107+
100108 int http_statuscode = httpResponse .getStatusLine ().getStatusCode ();
101109 if (http_statuscode < 200 || http_statuscode > 299 ) {
102110 String errMsg = String .format (
@@ -146,14 +154,9 @@ public HeadAttr headFile(String url, boolean qiniuDownLoadFlag) {
146154 }
147155
148156 return headAttr ;
149- } catch (Exception e ) {
150- log .error ("head file attr fail, url: {}, retry: {}/{}, exception: {}" , url , retry ,
151- maxRetryCount , e .toString ());
152- httpHead .abort ();
153- ++retry ;
154- }
155157 }
156158 return null ;
159+
157160 }
158161
159162 private void showDownloadProgress (String url , long byteTotal , long byteDownloadSofar ) {
0 commit comments