@@ -78,32 +78,33 @@ protected void doExecute(StagingContext ctx, Path dir, Map<String, String> vars)
78
78
static void download (StagingContext ctx , URL url , Path file )
79
79
throws IOException {
80
80
81
- try (BufferedInputStream bis = new BufferedInputStream (open (url , ctx ))) {
82
- try (OutputStream fos = Files .newOutputStream (file )) {
83
- int n ;
84
- long startTime = System .currentTimeMillis ();
85
- long progressTime = startTime ;
86
- long currentTime = startTime ;
87
- long totalSize = 0 ;
88
- long totalTime = 1 ;
89
- byte [] buffer = new byte [1024 ];
90
- while ((n = bis .read (buffer , 0 , buffer .length )) >= 0 ) {
91
- fos .write (buffer , 0 , n );
92
- totalSize += n ;
93
- currentTime = System .currentTimeMillis ();
94
- if (currentTime - progressTime >= 1000 ) {
95
- totalTime = (currentTime - startTime ) / 1000 ;
96
- progressTime = currentTime ;
97
- ctx .logInfo ("Downloading %s to %s (%s at %s/s)" ,
98
- url , file , measuredSize (totalSize ), measuredSize (totalSize / totalTime ));
99
- }
100
- }
81
+ try (BufferedInputStream bis = new BufferedInputStream (open (url , ctx ));
82
+ OutputStream fos = Files .newOutputStream (file )) {
83
+ int n ;
84
+ long startTime = System .currentTimeMillis ();
85
+ long progressTime = startTime ;
86
+ long currentTime = startTime ;
87
+ long totalSize = 0 ;
88
+ long totalTime = 1 ;
89
+ byte [] buffer = new byte [1024 ];
90
+ while ((n = bis .read (buffer , 0 , buffer .length )) >= 0 ) {
91
+ fos .write (buffer , 0 , n );
92
+ totalSize += n ;
93
+ currentTime = System .currentTimeMillis ();
101
94
if (currentTime - progressTime >= 1000 ) {
102
95
totalTime = (currentTime - startTime ) / 1000 ;
96
+ progressTime = currentTime ;
97
+ ctx .logInfo ("Downloading %s to %s (%s at %s/s)" ,
98
+ url , file , measuredSize (totalSize ), measuredSize (totalSize / totalTime ));
103
99
}
104
- ctx .logInfo ("Downloaded %s to %s (%s at %s/s)" ,
105
- url , file , measuredSize (totalSize ), measuredSize (totalSize / totalTime ));
106
100
}
101
+ if (currentTime - progressTime >= 1000 ) {
102
+ totalTime = (currentTime - startTime ) / 1000 ;
103
+ }
104
+ ctx .logInfo ("Downloaded %s to %s (%s at %s/s)" ,
105
+ url , file , measuredSize (totalSize ), measuredSize (totalSize / totalTime ));
106
+ } catch (IOException ex ) {
107
+ throw new IOException ("Failed to download " + url + " to " + file , ex );
107
108
}
108
109
}
109
110
0 commit comments