public int download ( ) { try { //if (url.startsWith("https://packagist.org") || url.startsWith("https://getcomposer.org")) { if ( url . startsWith ( "https://" ) ) { registerSSLContext ( client . getBackend ( ) ) ; } final HttpGet httpGet = new HttpGet ( url ) ; if ( httpGet . isAborted ( ) ) { httpGet . abort ( ) ; } client . execute ( httpGet , new FutureCallback < HttpResponse > ( ) { @ Override public void failed ( Exception e ) { for ( DownloadListenerInterface listener : listeners ) { listener . errorOccured ( e ) ; } } @ Override public void completed ( HttpResponse response ) { for ( DownloadListenerInterface listener : listeners ) { try { listener . dataReceived ( response . getEntity ( ) . getContent ( ) , httpGet . getURI ( ) . toString ( ) ) ; } catch ( Exception e ) { listener . errorOccured ( e ) ; } } } @ Override public void cancelled ( ) { for ( DownloadListenerInterface listener : listeners ) { listener . aborted ( httpGet . getURI ( ) . toString ( ) ) ; } } } ) ; httpGets . add ( httpGet ) ; // client.shutdown(); lastSlot = httpGets . size ( ) - 1 ; return lastSlot ; } catch ( Exception e ) { for ( DownloadListenerInterface listener : listeners ) { listener . errorOccured ( e ) ; } } return - 1 ; }
Starts the async download . The returned number is the internal slot for this download transfer which can be used as parameter in abort to stop this specific transfer .