@@ -333,73 +333,72 @@ private boolean unzip(File archiveFile, IPath destRelativePath) throws IOExcepti
333333 boolean result = true ;
334334
335335 // Get the zip file content.
336- ZipInputStream zipInput ;
337- zipInput = new ZipInputStream (new FileInputStream (archiveFile ));
338- // Get the zipped file list entry
339- ZipEntry zipEntry = zipInput .getNextEntry ();
336+ try (ZipInputStream zipInput = new ZipInputStream (new FileInputStream (archiveFile ))) {
337+ // Get the zipped file list entry
338+ ZipEntry zipEntry = zipInput .getNextEntry ();
340339
341- int countFiles = 0 ;
342- int countBytes = 0 ;
343- while (zipEntry != null && (result == true )) {
340+ int countFiles = 0 ;
341+ int countBytes = 0 ;
342+ while (zipEntry != null && (result == true )) {
344343
345- // Skip the folder definitions, we automatically create them.
346- if (!zipEntry .isDirectory ()) {
344+ // Skip the folder definitions, we automatically create them.
345+ if (!zipEntry .isDirectory ()) {
347346
348- String fileName = zipEntry .getName ();
347+ String fileName = zipEntry .getName ();
349348
350- IPath path = destRelativePath .append (fileName );
351- File outFile = PacksStorage .getFileObject (path .toString ());
352- if (!outFile .getParentFile ().exists ()) {
353- outFile .getParentFile ().mkdirs ();
354- }
355- fOut .println ("Writing \" " + outFile + "\" ..." );
356-
357- OutputStream output = new FileOutputStream (outFile );
358-
359- byte [] buf = new byte [1024 ];
360- int bytesRead ;
361- while ((bytesRead = zipInput .read (buf )) > 0 ) {
349+ IPath path = destRelativePath .append (fileName );
350+ File outFile = PacksStorage .getFileObject (path .toString ());
351+ if (!outFile .getParentFile ().exists ()) {
352+ outFile .getParentFile ().mkdirs ();
353+ }
354+ fOut .println ("Writing \" " + outFile + "\" ..." );
355+
356+ OutputStream output = new FileOutputStream (outFile );
357+
358+ byte [] buf = new byte [1024 ];
359+ int bytesRead ;
360+ while ((bytesRead = zipInput .read (buf )) > 0 ) {
361+ try {
362+ output .write (buf , 0 , bytesRead );
363+ } catch (IOException e ) {
364+ String msg = e .getMessage () + ", file: " + outFile .getName ();
365+ fOut .println ("Error: " + msg );
366+ DataUtils .reportError (msg );
367+
368+ result = false ;
369+ break ;
370+ }
371+ countBytes += bytesRead ;
372+ }
362373 try {
363- output .write ( buf , 0 , bytesRead );
374+ output .close ( );
364375 } catch (IOException e ) {
365376 String msg = e .getMessage () + ", file: " + outFile .getName ();
366377 fOut .println ("Error: " + msg );
367378 DataUtils .reportError (msg );
368379
369380 result = false ;
370- break ;
371381 }
372- countBytes += bytesRead ;
373- }
374- try {
375- output .close ();
376- } catch (IOException e ) {
377- String msg = e .getMessage () + ", file: " + outFile .getName ();
378- fOut .println ("Error: " + msg );
379- DataUtils .reportError (msg );
380-
381- result = false ;
382- }
383382
384- outFile .setReadOnly ();
385- ++countFiles ;
383+ outFile .setReadOnly ();
384+ ++countFiles ;
386385
387- }
386+ }
388387
389- zipEntry = zipInput .getNextEntry ();
390- }
388+ zipEntry = zipInput .getNextEntry ();
389+ }
391390
392- fMonitor .worked (1 );
391+ fMonitor .worked (1 );
393392
394- zipInput .closeEntry ();
395- zipInput .close ();
396- if (countBytes > 0 ) {
397- fOut .println (countFiles + " files written, " + StringUtils .convertSizeToString (countBytes ) + "." );
398- } else {
399- fOut .println ("No files written." );
400- result = false ;
393+ zipInput .closeEntry ();
394+ if (countBytes > 0 ) {
395+ fOut .println (countFiles + " files written, " + StringUtils .convertSizeToString (countBytes ) + "." );
396+ } else {
397+ fOut .println ("No files written." );
398+ result = false ;
399+ }
400+ return result ;
401401 }
402- return result ;
403402 }
404403
405404}
0 commit comments