@Override protected Void doInBackground(Void... voids){
  HttpsURLConnection con=null;
  InputStream inputStream=null;
  FileOutputStream outputStream=null;
  try {
    con=NetCipher.getHttpsURLConnection(fileURL);
    int responseCode=con.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_OK) {
      fileSize=con.getContentLength();
      inputStream=new BufferedInputStream(con.getInputStream());
      outputStream=new FileOutputStream(saveFilePath);
      int bufferSize=8192;
      int downloaded=0;
      int bytesRead=-1;
      byte[] buffer=new byte[bufferSize];
      while ((bytesRead=inputStream.read(buffer)) != -1) {
        outputStream.write(buffer,0,bytesRead);
        downloaded+=bytesRead;
        if (downloaded % 50000 < bufferSize) {
          publishProgress(downloaded);
        }
      }
      publishProgress(bufferSize);
    }
 else {
      Log.i(TAG,"No file to download. Server replied HTTP code: " + responseCode);
    }
  }
 catch (  IOException e) {
    Log.e(TAG,"No file to download. Server replied HTTP code: ",e);
    e.printStackTrace();
  }
 finally {
    try {
      if (outputStream != null) {
        outputStream.close();
      }
      if (inputStream != null) {
        inputStream.close();
      }
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
    if (con != null) {
      con.disconnect();
    }
  }
  return null;
}

@ Override protected Void doInBackground ( Void ... voids ) { HttpsURLConnection con = null ; InputStream inputStream = null ; FileOutputStream outputStream = null ; try { con = NetCipher . getHttpsURLConnection ( fileURL ) ; int responseCode = con . getResponseCode ( ) ; if ( responseCode == HttpURLConnection . HTTP_OK ) { fileSize = con . getContentLength ( ) ; inputStream = new BufferedInputStream ( con . getInputStream ( ) ) ; outputStream = new FileOutputStream ( saveFilePath ) ; int bufferSize = 8192 ; int downloaded = 0 ; int bytesRead = - 1 ; byte [ ] buffer = new byte [ bufferSize ] ; while ( ( bytesRead = inputStream . read ( buffer ) ) != - 1 ) { outputStream . write ( buffer , 0 , bytesRead ) ; downloaded += bytesRead ; if ( downloaded % 50000 < bufferSize ) { publishProgress ( downloaded ) ; } } publishProgress ( bufferSize ) ; } else { Log . i ( TAG , "No file to download. Server replied HTTP code: " + responseCode ) ; } } catch ( IOException e ) { Log . e ( TAG , "No file to download. Server replied HTTP code: " , e ) ; e . printStackTrace ( ) ; } finally { try { if ( outputStream != null ) { outputStream . close ( ) ; } if ( inputStream != null ) { inputStream . close ( ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } if ( con != null ) { con . disconnect ( ) ; } } return null ; }
asynctask impl : executed in background thread does the download
