public boolean downloadToStream(ImageTask imageTask, String urlString, OutputStream outputStream, ProgressUpdateHandler progressUpdateHandler) {
        disableConnectionReuseIfNecessary();
        HttpURLConnection urlConnection = null;
        BufferedOutputStream out = null;
        BufferedInputStream in = null;

        try {
            final URL url = new URL(urlString);
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setReadTimeout(0);
            int len = urlConnection.getContentLength();
            int total = 0;
            in = new BufferedInputStream(urlConnection.getInputStream(), IO_BUFFER_SIZE);
            out = new BufferedOutputStream(outputStream, IO_BUFFER_SIZE);
            int b;
            while ((b = in.read()) != -1) {
                total++;
                out.write(b);
                if (progressUpdateHandler != null) {
                    progressUpdateHandler.onProgressUpdate(total, len);
                }
            }
            return true;
        } catch (final IOException e) {
            CLog.e(LOG_TAG, "Error in downloadBitmap - " + e);
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (final IOException e) {
            }
        }
        return false;
    }
public boolean downloadToStream(ImageTask imageTask, String urlString, OutputStream outputStream, ProgressUpdateHandler progressUpdateHandler) {
        disableConnectionReuseIfNecessary();
        HttpURLConnection urlConnection = null;
        BufferedOutputStream out = null;
        BufferedInputStream in = null;

        try {
            final URL url = new URL(urlString);
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setReadTimeout(0);
            int len = urlConnection.getContentLength();
            int total = 0;
            in = new BufferedInputStream(urlConnection.getInputStream(), IO_BUFFER_SIZE);
            out = new BufferedOutputStream(outputStream, IO_BUFFER_SIZE);
            int b;
            while ((b = in.read()) != -1) {
                total++;
                out.write(b);
                if (progressUpdateHandler != null) {
                    progressUpdateHandler.onProgressUpdate(total, len);
                }
            }
            return true;
        } catch (final IOException e) {
            CLog.e(LOG_TAG, "Error in downloadBitmap - " + e);
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (final IOException e) {
            }
        }
        return false;
    }
public boolean downloadToStream ( ImageTask imageTask , String urlString , OutputStream outputStream , ProgressUpdateHandler progressUpdateHandler ) { disableConnectionReuseIfNecessary ( ) ; HttpURLConnection urlConnection = null ; BufferedOutputStream out = null ; BufferedInputStream in = null ; try { final URL url = new URL ( urlString ) ; urlConnection = ( HttpURLConnection ) url . openConnection ( ) ; urlConnection . setReadTimeout ( 0 ) ; int len = urlConnection . getContentLength ( ) ; int total = 0 ; in = new BufferedInputStream ( urlConnection . getInputStream ( ) , IO_BUFFER_SIZE ) ; out = new BufferedOutputStream ( outputStream , IO_BUFFER_SIZE ) ; int b ; while ( ( b = in . read ( ) ) != - 1 ) { total ++ ; out . write ( b ) ; if ( progressUpdateHandler != null ) { progressUpdateHandler . onProgressUpdate ( total , len ) ; } } return true ; } catch ( final IOException e ) { CLog . e ( LOG_TAG , "Error in downloadBitmap - " + e ) ; } finally { if ( urlConnection != null ) { urlConnection . disconnect ( ) ; } try { if ( out != null ) { out . close ( ) ; } if ( in != null ) { in . close ( ) ; } } catch ( final IOException e ) { } } return false ; }
Download a bitmap from a URL and write the content to an output stream.
Download a bitmap from a URL and write the content to an output stream .