private void stream ( InputStream is , File destFile ) throws IOException { try { startProgress ( ) ; OutputStream os = new FileOutputStream ( destFile ) ; boolean finished = false ; try { byte [ ] buf = new byte [ 1024 * 10 ] ; int read ; while ( ( read = is . read ( buf ) ) >= 0 ) { os . write ( buf , 0 , read ) ; processedBytes += read ; logProgress ( ) ; } os . flush ( ) ; finished = true ; } finally { os . close ( ) ; if ( ! finished ) { destFile . delete ( ) ; } } } finally { is . close ( ) ; completeProgress ( ) ; } }
Copy bytes from an input stream to a file and log progress