public static boolean downloadUrlToStream(String urlString,OutputStream outputStream){
  disableConnectionReuseIfNecessary();
  HttpURLConnection urlConnection=null;
  BufferedOutputStream out=null;
  BufferedInputStream in=null;
  try {
    final URL url=new URL(urlString);
    urlConnection=(HttpURLConnection)url.openConnection();
    in=new BufferedInputStream(urlConnection.getInputStream(),IO_BUFFER_SIZE);
    out=new BufferedOutputStream(outputStream,IO_BUFFER_SIZE);
    int b;
    while ((b=in.read()) != -1) {
      out.write(b);
    }
    return true;
  }
 catch (  final IOException e) {
    Log.e(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 static boolean downloadUrlToStream ( String urlString , OutputStream outputStream ) { disableConnectionReuseIfNecessary ( ) ; HttpURLConnection urlConnection = null ; BufferedOutputStream out = null ; BufferedInputStream in = null ; try { final URL url = new URL ( urlString ) ; urlConnection = ( HttpURLConnection ) url . openConnection ( ) ; in = new BufferedInputStream ( urlConnection . getInputStream ( ) , IO_BUFFER_SIZE ) ; out = new BufferedOutputStream ( outputStream , IO_BUFFER_SIZE ) ; int b ; while ( ( b = in . read ( ) ) != - 1 ) { out . write ( b ) ; } return true ; } catch ( final IOException e ) { Log . e ( 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 .
