public IStatus run(IProgressMonitor monitor){
  InputStream input=null;
  FileOutputStream output=null;
  IStatus jobStatus=Status.OK_STATUS;
  byte[] b=new byte[1024];
  int bytesRead;
  try {
    HttpURLConnection connection=(HttpURLConnection)url.openConnection();
    input=url.openStream();
    long totalBytesRead=0L;
    int responseStatusCode=connection.getResponseCode();
    if (responseStatusCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
      jobStatus=new Status(Status.ERROR,CorePlugin.PLUGIN_ID,MessageFormat.format("Remote ServerError: {0} ({1})",responseStatusCode,connection.getResponseMessage()));
    }
    long contentLength=connection.getContentLength();
    output=new FileOutputStream(target);
    monitor.beginTask("Downloading " + url.toString(),(int)contentLength);
    while (jobStatus == Status.OK_STATUS) {
      if (contentLength > 0 && totalBytesRead >= contentLength) {
        break;
      }
      bytesRead=input.read(b);
      if (bytesRead == -1) {
        break;
      }
      output.write(b,0,bytesRead);
      totalBytesRead+=bytesRead;
      monitor.worked(bytesRead);
      if (monitor.isCanceled()) {
        jobStatus=Status.CANCEL_STATUS;
        break;
      }
    }
  }
 catch (  MalformedURLException e) {
    jobStatus=new Status(Status.ERROR,CorePlugin.PLUGIN_ID,"Malformed URL: " + url.toExternalForm(),e);
  }
catch (  IOException e) {
    jobStatus=new Status(Status.ERROR,CorePlugin.PLUGIN_ID,"IO error while downloading " + url.toExternalForm(),e);
  }
  closeStreams(input,output);
  return jobStatus;
}

public IStatus run ( IProgressMonitor monitor ) { InputStream input = null ; FileOutputStream output = null ; IStatus jobStatus = Status . OK_STATUS ; byte [ ] b = new byte [ 1024 ] ; int bytesRead ; try { HttpURLConnection connection = ( HttpURLConnection ) url . openConnection ( ) ; input = url . openStream ( ) ; long totalBytesRead = 0L ; int responseStatusCode = connection . getResponseCode ( ) ; if ( responseStatusCode >= HttpURLConnection . HTTP_BAD_REQUEST ) { jobStatus = new Status ( Status . ERROR , CorePlugin . PLUGIN_ID , MessageFormat . format ( "Remote ServerError: {0} ({1})" , responseStatusCode , connection . getResponseMessage ( ) ) ) ; } long contentLength = connection . getContentLength ( ) ; output = new FileOutputStream ( target ) ; monitor . beginTask ( "Downloading " + url . toString ( ) , ( int ) contentLength ) ; while ( jobStatus == Status . OK_STATUS ) { if ( contentLength > 0 && totalBytesRead >= contentLength ) { break ; } bytesRead = input . read ( b ) ; if ( bytesRead == - 1 ) { break ; } output . write ( b , 0 , bytesRead ) ; totalBytesRead += bytesRead ; monitor . worked ( bytesRead ) ; if ( monitor . isCanceled ( ) ) { jobStatus = Status . CANCEL_STATUS ; break ; } } } catch ( MalformedURLException e ) { jobStatus = new Status ( Status . ERROR , CorePlugin . PLUGIN_ID , "Malformed URL: " + url . toExternalForm ( ) , e ) ; } catch ( IOException e ) { jobStatus = new Status ( Status . ERROR , CorePlugin . PLUGIN_ID , "IO error while downloading " + url . toExternalForm ( ) , e ) ; } closeStreams ( input , output ) ; return jobStatus ; }
executes the downloadrunnable using the provided monitor to update the user and provide cancel capabilities .
