question: public static void copyStream ( InputStream is , OutputStream os , long length , DownloadFileManager . OnDownloadListener listener ) { final int buffer_size = 1024 ; int totalLen = 0 ; try { byte [ ] bytes = new byte [ buffer_size ] ; while ( true ) { int count = is . read ( bytes , 0 , buffer_size ) ; if ( count == - 1 ) { listener . onFinishDownload ( ) ; break ; } if ( length != - 1 && listener != null ) { totalLen = totalLen + count ; listener . onProgress ( totalLen ) ; } os . write ( bytes , 0 , count ) ; } } catch ( Exception ex ) { ex . printStackTrace ( ) ; } }
target:  copy stream with progress listener