@@ -228,14 +228,15 @@ private boolean downloadModule(ModuleConfig module) {
228
228
authHeader .forEach ((k , v ) -> {
229
229
conn .setRequestProperty (k , v );
230
230
});
231
- InputStream inStream = conn .getInputStream ();
232
231
String path = module .getPackageConfig ().getStoragePath () + "/" + module .getPackageConfig ().getFileName ();
233
- FileOutputStream fs = new FileOutputStream (path );
234
- LOGGER .info ("save path {}" , path );
235
- int byteRead ;
236
- byte [] buffer = new byte [DOWNLOAD_PACKAGE_READ_BUFF_SIZE ];
237
- while ((byteRead = inStream .read (buffer )) != -1 ) {
238
- fs .write (buffer , 0 , byteRead );
232
+ try (InputStream inputStream = conn .getInputStream ();
233
+ FileOutputStream outputStream = new FileOutputStream (path )) {
234
+ LOGGER .info ("save path {}" , path );
235
+ int byteRead ;
236
+ byte [] buffer = new byte [DOWNLOAD_PACKAGE_READ_BUFF_SIZE ];
237
+ while ((byteRead = inputStream .read (buffer )) != -1 ) {
238
+ outputStream .write (buffer , 0 , byteRead );
239
+ }
239
240
}
240
241
if (isPackageDownloaded (module )) {
241
242
return true ;
@@ -284,16 +285,13 @@ public void stop() throws Exception {
284
285
285
286
private static String calcFileMd5 (String path ) {
286
287
BigInteger bi = null ;
287
- try {
288
- byte [] buffer = new byte [ DOWNLOAD_PACKAGE_READ_BUFF_SIZE ] ;
289
- int len = 0 ;
288
+ byte [] buffer = new byte [ DOWNLOAD_PACKAGE_READ_BUFF_SIZE ];
289
+ int len = 0 ;
290
+ try ( FileInputStream fileInputStream = new FileInputStream ( path )) {
290
291
MessageDigest md = MessageDigest .getInstance ("MD5" );
291
- File f = new File (path );
292
- FileInputStream fis = new FileInputStream (f );
293
- while ((len = fis .read (buffer )) != -1 ) {
292
+ while ((len = fileInputStream .read (buffer )) != -1 ) {
294
293
md .update (buffer , 0 , len );
295
294
}
296
- fis .close ();
297
295
byte [] b = md .digest ();
298
296
bi = new BigInteger (1 , b );
299
297
} catch (NoSuchAlgorithmException e ) {
0 commit comments