public static boolean copyStream(InputStream is,OutputStream os,CopyListener listener,int bufferSize) throws IOException {
  int current=0;
  int total=is.available();
  if (total <= 0) {
    total=DEFAULT_IMAGE_TOTAL_SIZE;
  }
  final byte[] bytes=new byte[bufferSize];
  int count;
  if (shouldStopLoading(listener,current,total))   return false;
  while ((count=is.read(bytes,0,bufferSize)) != -1) {
    os.write(bytes,0,count);
    current+=count;
    if (shouldStopLoading(listener,current,total))     return false;
  }
  os.flush();
  return true;
}

public static boolean copyStream ( InputStream is , OutputStream os , CopyListener listener , int bufferSize ) throws IOException { int current = 0 ; int total = is . available ( ) ; if ( total <= 0 ) { total = DEFAULT_IMAGE_TOTAL_SIZE ; } final byte [ ] bytes = new byte [ bufferSize ] ; int count ; if ( shouldStopLoading ( listener , current , total ) ) return false ; while ( ( count = is . read ( bytes , 0 , bufferSize ) ) != - 1 ) { os . write ( bytes , 0 , count ) ; current += count ; if ( shouldStopLoading ( listener , current , total ) ) return false ; } os . flush ( ) ; return true ; }
copies stream , fires progress events by listener , can be interrupted by listener .
