Download resource to the given file
325888
private boolean download( URL target, File file )
    {

        _log.addDebug( "JarDiffHandler:  Doing download" );

        boolean ret = true;
        boolean delete = false;
        // use bufferedstream for better performance
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try
        {
            in = new BufferedInputStream( target.openStream() );
            out = new BufferedOutputStream( new FileOutputStream( file ) );
            int read = 0;
            int totalRead = 0;
            byte[] buf = new byte[BUF_SIZE];
            while ( ( read = in.read( buf ) ) != -1 )
            {
                out.write( buf, 0, read );
                totalRead += read;
            }

            _log.addDebug( "total read: " + totalRead );
            _log.addDebug( "Wrote URL " + target.toString() + " to file " + file );

        }
        catch ( IOException ioe )
        {

            _log.addDebug( "Got exception while downloading resource: " + ioe );

            ret = false;

            if ( file != null )
            {
                delete = true;
            }

        }
        finally
        {

            try
            {
                in.close();
                in = null;
            }
            catch ( IOException ioe )
            {
                _log.addDebug( "Got exception while downloading resource: " + ioe );
            }

            try
            {
                out.close();
                out = null;
            }
            catch ( IOException ioe )
            {
                _log.addDebug( "Got exception while downloading resource: " + ioe );
            }

            if ( delete )
            {
                file.delete();
            }

        }
        return ret;
    }
575133
def download(self, force=False, silent=False):
        """"""
        def _download():
            if self.url.startswith("http"):
                self._download_http(silent=silent)
            elif self.url.startswith("ftp"):
                self._download_ftp(silent=silent)
            else:
                raise ValueError("Invalid URL %s" % self.url)
            logger.debug("Moving %s to %s" % (
                self._temp_file_name,
                self.destination))
            shutil.move(self._temp_file_name, self.destination)
            logger.debug("Successfully downloaded %s" % self.url)

        try:
            is_already_downloaded = os.path.isfile(self.destination)
            if is_already_downloaded:
                if force:
                    try:
                        os.remove(self.destination)
                    except Exception:
                        logger.error("Cannot delete %s" % self.destination)
                    logger.info(
                        "Downloading %s to %s" % (self.url, self.destination))
                    logger.debug(
                        "Downloading %s to %s" % (self.url,
                                                  self._temp_file_name))
                    _download()
                else:
                    logger.info(("File %s already exist. Use force=True if you"
                                 " would like to overwrite it.") %
                                self.destination)
            else:
                _download()
        finally:
            try:
                os.remove(self._temp_file_name)
            except OSError:
                pass
528711
def download_resource(self, download_url, target, guard):
        
        download_url = download_url.strip()
        if not os.path.isabs(target):
            target = os.path.join(config.config_dir, target)

        if os.path.exists(os.path.join(target, guard)):
            self.LOG.info("Already have '%s' in '%s'..." % (download_url, target))
            return

        if not os.path.isdir(target):
            os.makedirs(target)

        self.LOG.info("Downloading '%s' to '%s'..." % (download_url, target))
        with closing(urllib2.urlopen(download_url)) as url_handle:
            if download_url.endswith(".zip"):
                with closing(ZipFile(StringIO(url_handle.read()))) as zip_handle:  # pylint: disable=no-member
                    zip_handle.extractall(target)  # pylint: disable=no-member
            else:
                with open(os.path.join(target, guard), "wb") as file_handle:
                    shutil.copyfileobj(url_handle, file_handle)
125610
def download_file(self, file_id, dest):
        
        f = self.getFile(file_id)
        try:
            d = dest if _isfile(dest) else open(dest, 'wb')

            r = api.download((self._token, f['file_path']), preload_content=False)

            while 1:
                data = r.read(self._file_chunk_size)
                if not data:
                    break
                d.write(data)
        finally:
            if not _isfile(dest) and 'd' in locals():
                d.close()

            if 'r' in locals():
                r.release_conn()
364478
def download_file(url, path, session=None, params=None):
    

    if url[0:2] == '//':
        url = 'https://' + url[2:]

    # Use a temporary file so that we don't import incomplete files.
    tmp_path = path + '.tmp'

    if session and params:
        r = session.get( url, params=params, stream=True )
    elif session and not params:
        r = session.get( url, stream=True )
    else:
        r = requests.get(url, stream=True)
    with open(tmp_path, 'wb') as f:
        total_length = int(r.headers.get('content-length', 0))
        for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length / 1024) + 1):
            if chunk:  # filter out keep-alive new chunks
                f.write(chunk)
                f.flush()

    os.rename(tmp_path, path)

    return path
444808
public File download(String pathToFile, String extension) {
        return fileDownloadRequest.download(pathToFile, extension);
    }
179736
def download(self, FILENAME=None):
        """"""
        resultFilename = None
        url = self.__url+'/services'                
        result = Util.retrieveJsonResponseFromServer(url)
        dataItems = result['data']
        for item in dataItems:
            plugin = Plugin(item)        
            result = plugin.getParameterByValue("fr.cnes.sitools.resources.order.DirectOrderResource")            
            if result == None:
                continue
            else:
                urlParameter = plugin.getParameterByType('PARAMETER_ATTACHMENT')
                urlPlugin = urlParameter.getValue()
                encodingParameter = plugin.getParameterByName('archiveType')
                encodingPlugin = encodingParameter.getValue()
                query = self.getQueries()
                query.setBaseUrl(self.__url + urlPlugin)
                url = query.getUrl()                
                (filename, header) = Util.urlretrieve('%s' % url, FILENAME)
                if FILENAME == None:
                    os.rename(filename, filename + "." + encodingPlugin)
                    resultFilename = filename + "." + encodingPlugin
                else:
                    os.rename(FILENAME, FILENAME + "." + encodingPlugin)
                    resultFilename = FILENAME + "." + encodingPlugin
                break
        return resultFilename
1319777
async def download_file(self, file_id, dest):
        
        f = await self.getFile(file_id)

        try:
            d = dest if isinstance(dest, io.IOBase) else open(dest, 'wb')

            session, request = api.download((self._token, f['file_path']))

            async with session:
                async with request as r:
                    while 1:
                        chunk = await r.content.read(self._file_chunk_size)
                        if not chunk:
                            break
                        d.write(chunk)
                        d.flush()
        finally:
            if not isinstance(dest, io.IOBase) and 'd' in locals():
                d.close()
1096150
def file_download(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/download' % object_id, input_params, always_retry=always_retry, **kwargs)
1235549
def download(self, url, path=None, force=False):
        """"""
        logger.debug(str((url, path, force)))
        method = self._download
        return self._create_worker(method, url, path=path, force=force)
873592
def _download_and_clean_file(filename, url):
  """"""
  temp_file, _ = urllib.request.urlretrieve(url)
  with tf.gfile.Open(temp_file, 'r') as temp_eval_file:
    with tf.gfile.Open(filename, 'w') as eval_file:
      for line in temp_eval_file:
        line = line.strip()
        line = line.replace(', ', ',')
        if not line or ',' not in line:
          continue
        if line[-1] == '.':
          line = line[:-1]
        line += '\n'
        eval_file.write(line)
  tf.gfile.Remove(temp_file)
440150
def downloadFileFromUrl(self, url):
		""""""
		fullurl = self.baseUrl + url
		try:
			urlobj = urllib2.urlopen(fullurl)
			contents = urlobj.read()
		except urllib2.HTTPError, e:
			self.printd("HTTP error:", e.code, url)
			return None
		except urllib2.URLError, e:
			self.printd("URL error:", e.code, url)
			return None
		self.printd("Fetched '%s' (size %d bytes)" % (fullurl, len(contents)))
		return contents
171947
def downloadFile(url,outfile=None): 
    '''  '''
    if not outfile:
        outfile = url.split('/')[-1]
    r = requests.get(url, stream=True)
    with open(outfile, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk: 
                f.write(chunk)
    return outfile
5172
def download_to(self, folder):
        '''
        
        '''
        urlretrieve(self.maven_url, os.path.join(folder, self.filename))
34762
def download_file(file_id, file_name):
    ''''''
    extracted_out_dir = os.path.join(app.config['UPLOAD_FOLDER'], file_id)
    return send_file(os.path.join(extracted_out_dir, file_name))
655150
def download_file(path, local_drive_path)
      uri = URI.parse(Addressable::URI.escape(@url + path))
      http_request = build_http_object(uri)
      req = build_request(:get, uri, {}, @api_version.to_s)

      http_request.start do |http|
        http.request(req) do |res|
          response_handler(res) unless res.code.to_i.between?(200, 204)
          File.open(local_drive_path, 'wb') do |file|
            res.read_body do |segment|
              file.write(segment)
            end
          end
        end
      end
      true
    end
118460
def download(self, remote_url, local_path, buffer_size=8 * 1024):
        """"""
        bucket, key = _parse_url(remote_url)

        response_file = self.call("GetObject", bucket=bucket, key=key)['Body']
        with open(local_path, 'wb') as fp:
            buf = response_file.read(buffer_size)
            while buf:
                fp.write(buf)
                buf = response_file.read(buffer_size)