@@ -282,23 +282,22 @@ protected String doInBackground(Void... args) {
282282
283283 if (dbFile .getAbsolutePath ().endsWith (".zip" )) {
284284 // uncompress first
285- try {
286- final FileInputStream fileInputStream = new FileInputStream (dbFile .getAbsolutePath ());
287- final ZipInputStream zip_stream = new ZipInputStream (new BufferedInputStream (fileInputStream ));
285+ try (final FileInputStream fileInputStream = new FileInputStream (dbFile .getAbsolutePath ());
286+ final ZipInputStream zip_stream = new ZipInputStream (new BufferedInputStream (fileInputStream ))) {
288287 ZipEntry zipEntry = zip_stream .getNextEntry ();
289288 if ((zipEntry != null ) && zipEntry .isDirectory ())
290289 zipEntry = zip_stream .getNextEntry ();
291290 if (zipEntry != null ) {
292291 String filename = zipEntry .getName ();
293292 if (filename .endsWith (".sqlite" )) {
294293 String output_filename = dbFile .getAbsolutePath ().replaceFirst (".zip$" , ".sqlite" );
295- FileOutputStream fout = new FileOutputStream (output_filename );
296- byte [] buffer = new byte [4096 ];
297- int count = 0 ;
298- while ((count = zip_stream .read (buffer )) != -1 ) {
299- fout .write (buffer , 0 , count );
294+ try (FileOutputStream fout = new FileOutputStream (output_filename )) {
295+ byte [] buffer = new byte [4096 ];
296+ int count ;
297+ while ((count = zip_stream .read (buffer )) != -1 ) {
298+ fout .write (buffer , 0 , count );
299+ }
300300 }
301- fout .close ();
302301 dbFile = new File (output_filename );
303302 delete_file = dbFile ;
304303 Log .d (TAG , "New filename: " + output_filename );
@@ -314,9 +313,6 @@ protected String doInBackground(Void... args) {
314313 return msg ;
315314 }
316315
317- zip_stream .close ();
318- fileInputStream .close ();
319-
320316 } catch (IOException e ) {
321317 String msg = "Could not open file" ;
322318 JoH .static_toast_long (msg );
0 commit comments