Download the file from the given URL to the specified target

@param appcast The appcast content
@param targetDir The target download dir (update directory)
@return Path to the downloaded update file
@throws IOException in case of an error
427163
public Path download(Appcast appcast, Path targetDir) throws IOException, Exception {
        Path downloaded = null;
        Enclosure enclosure = appcast.getLatestEnclosure();
        if (enclosure != null) {
            String url = enclosure.getUrl();
            if (url != null && !url.isEmpty()) {
                URL enclosureUrl = new URL(url);
                String targetName = url.substring( url.lastIndexOf('/')+1, url.length() );
                long length = enclosure.getLength();

                File tmpFile = null;
                ReadableByteChannel rbc = null;
                FileOutputStream fos = null;
                try {
                    tmpFile = File.createTempFile("ac-", ".part");
                    rbc = Channels.newChannel(enclosureUrl.openStream());
                    fos = new FileOutputStream(tmpFile);
                    fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);

                    // Verify if file is ok
                    // Check size
                    if (length > 0) {
                        long size = Files.size(tmpFile.toPath());
                        if (length != size) {
                            throw new Exception("Downloaded file has wrong size! Expected: " + length + " -- Actual: " + size);
                        }
                    }

                    // Check MD5/DSA Signature
                    String md5 = enclosure.getMd5();
                    if (md5 != null) {
                        MessageDigest md = MessageDigest.getInstance("MD5");
                        md.reset();
                        byte[] bytes = new byte[2048];
                        int numBytes;
                        try (FileInputStream is = new FileInputStream(tmpFile)) {
                            while ((numBytes = is.read(bytes)) != -1) {
                                md.update(bytes, 0, numBytes);
                            }
                        }
                        String hash = toHex(md.digest());
                        if (!md5.equalsIgnoreCase(hash)) {
                            throw new Exception("Downloaded file has wrong MD5 hash! Expected: " + md5 + " -- Actual: " + hash);
                        }
                    }

                    // Copy file to target dir
                    downloaded = Files.copy(tmpFile.toPath(), targetDir.resolve(targetName), StandardCopyOption.REPLACE_EXISTING);
                } finally {
                    try { if (fos != null) fos.close(); } catch (IOException e) { /*  ignore */ }
                    try { if (rbc != null) rbc.close(); } catch (IOException e) { /*  ignore */ }
                    if (tmpFile != null) {
                        Files.deleteIfExists(tmpFile.toPath());
                    }
                }
            }
        }

        return downloaded;
    }
459131
public Downloader newDownloader(URL source, Path destination, ProgressListener progressListener) {
    return new Downloader(source, destination, userAgentString, progressListener);
  }
1098287
function httpDownload(targetPath, path, file)  {
    switch (configuredDownloadClient) {
        case "curl": return sh`curl -A curl --progress -o "${targetPath}/${file}" "https://transfer.sh/${path}/${file}"`;
        case "wget": return sh`wget --progress=dot -O "${targetPath}/${file}" "https://transfer.sh/${path}/${file}"`;
        case "fetch": return sh`fetch -q -o "${targetPath}/${file}" "https://transfer.sh/${path}/${file}"`;
        default: throw new Error("No configured download client");
    }
}
453409
public void updateDownLoadUrl(final String gavc, final String downLoadUrl) {
        final DbArtifact artifact = getArtifact(gavc);
        repositoryHandler.updateDownloadUrl(artifact, downLoadUrl);
    }
520496
private function downloadNewVersion()
    {
        // check for permissions in local filesystem before start downloading files
        if (!is_writable($this->currentInstallerFile)) {
            throw new IOException('Symfony Installer update failed: the "'.$this->currentInstallerFile.'" file could not be written');
        }

        if (!is_writable($this->tempDir)) {
            throw new IOException('Symfony Installer update failed: the "'.$this->tempDir.'" directory used to download files temporarily could not be written');
        }

        if (false === $newInstaller = $this->getUrlContents($this->remoteInstallerFile)) {
            throw new \RuntimeException('The new version of the Symfony Installer couldn\'t be downloaded from the server.');
        }

        $newInstallerPermissions = $this->currentInstallerFile ? fileperms($this->currentInstallerFile) : 0777 & ~umask();
        $this->fs->dumpFile($this->newInstallerFile, $newInstaller, $newInstallerPermissions);

        return $this;
    }
1341264
public static void downloadImageToFile(String url, Path file) throws IOException {


        if (Files.exists(file.getParent())) {
            URL urlObject = new URL(url);
            URLConnection connection = urlObject.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
            connection.setRequestProperty("Referer", "http://www.google.com");


            FileUtils.copyInputStreamToFile(connection.getInputStream(), file.toFile());
        }
    }
581205
protected final void downloadFile(final URI source, final File destination) throws IOException {
        Validate.validState(!isStopped, "Cannot download file when the crawler is not started.");
        Validate.validState(!isStopping, "Cannot download file when the crawler is stopping.");
        Validate.notNull(source, "The source URL cannot be null.");
        Validate.notNull(destination, "The destination file cannot be null.");

        HttpGet request = new HttpGet(source);
        try (CloseableHttpResponse response = httpClient.execute(request)) {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                FileUtils.copyInputStreamToFile(entity.getContent(), destination);
            }
        }
    }
618897
private File getTargetDir( File path)
    {
    return
      path == null?
      targetDir_ :

      path.isAbsolute()?
      path :

      new File( targetDir_, path.getPath());
    }
683120
private File transfer2SpecifyDir(File srcFile, String targetDirPath, String fileName,
                                     boolean isMove) throws Exception {

        // make dir
        OsUtil.makeDirs(targetDirPath);

        File targetPath = new File(OsUtil.pathJoin(targetDirPath, fileName));
        // 从下载文件 复制/mv 到targetPath 原子性的做转移
        OsUtil.transferFileAtom(srcFile, targetPath, isMove);
        return targetPath;

    }
551751
public void downloadTo(Path path, BlobSourceOption... options) {
    try (OutputStream outputStream = Files.newOutputStream(path);
        ReadChannel reader = reader(options)) {
      WritableByteChannel channel = Channels.newChannel(outputStream);
      ByteBuffer bytes = ByteBuffer.allocate(DEFAULT_CHUNK_SIZE);
      while (reader.read(bytes) > 0) {
        bytes.flip();
        channel.write(bytes);
        bytes.clear();
      }
    } catch (IOException e) {
      throw new StorageException(e);
    }
  }
1276958
public void download(String path, String fileName, File outFile) {
		if (outFile.isDirectory()) {
			outFile = new File(outFile, fileName);
		}
		if (false == outFile.exists()) {
			FileUtil.touch(outFile);
		}
		try (OutputStream out = FileUtil.getOutputStream(outFile)) {
			download(path, fileName, out);
		} catch (IOException e) {
			throw new FtpException(e);
		}
	}
863704
def download_file(self, url, target, cwd=None):
        
        if not url:
            return
        info('Downloading {} from {}'.format(self.name, url))

        if cwd:
            target = join(cwd, target)

        parsed_url = urlparse(url)
        if parsed_url.scheme in ('http', 'https'):
            def report_hook(index, blksize, size):
                if size <= 0:
                    progression = '{0} bytes'.format(index * blksize)
                else:
                    progression = '{0:.2f}%'.format(
                        index * blksize * 100. / float(size))
                if "CI" not in environ:
                    stdout.write('- Download {}\r'.format(progression))
                    stdout.flush()

            if exists(target):
                unlink(target)

            # Download item with multiple attempts (for bad connections):
            attempts = 0
            while True:
                try:
                    urlretrieve(url, target, report_hook)
                except OSError as e:
                    attempts += 1
                    if attempts >= 5:
                        raise e
                    stdout.write('Download failed retrying in a second...')
                    time.sleep(1)
                    continue
                break
            return target
        elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
            if isdir(target):
                with current_directory(target):
                    shprint(sh.git, 'fetch', '--tags')
                    if self.version:
                        shprint(sh.git, 'checkout', self.version)
                    shprint(sh.git, 'pull')
                    shprint(sh.git, 'pull', '--recurse-submodules')
                    shprint(sh.git, 'submodule', 'update', '--recursive')
            else:
                if url.startswith('git+'):
                    url = url[4:]
                shprint(sh.git, 'clone', '--recursive', url, target)
                if self.version:
                    with current_directory(target):
                        shprint(sh.git, 'checkout', self.version)
                        shprint(sh.git, 'submodule', 'update', '--recursive')
            return target
106299
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;
	}
1364476
public Response download(String url, File destination) throws IOException {
		return download(url, destination, (String[]) null);
	}
936557
def download(self, target_relpath, download_in_toto_metadata=True):
        '''
        
        '''
        return self.__get_target(target_relpath, download_in_toto_metadata=download_in_toto_metadata)
1087978
public void connect() throws IOException {
        if (this.connected) {
            return;
        }
        
        this.downloadFile = File.createTempFile(CLASSNAME, null, TMPDIR);
        try {
            String [] cmd = getCommand(this.url, this.downloadFile);    
            if (LOGGER.isLoggable(Level.FINE)) {
                StringBuffer buffer = new StringBuffer();
                for (int i = 0; i < cmd.length; i++) {
                    if (i > 0) {
                        buffer.append(" ");
                    }
                    buffer.append(cmd[i]);
                }
                LOGGER.fine("Command: " + buffer.toString());
            }
            ProcessResult pr = ProcessUtils.exec(cmd);
            if (pr.getResult() != 0) {
                LOGGER.info(Arrays.toString(cmd) + " returned non-null " + pr.getResult());
            }
            // Assume download went smoothly.
            this.connected = true;
        } catch (IOException ioe) {
            // Clean up my tmp file.
            this.downloadFile.delete();
            this.downloadFile = null;
            // Rethrow.
            throw ioe;
        }
    }
5172
def download_to(self, folder):
        '''
        
        '''
        urlretrieve(self.maven_url, os.path.join(folder, self.filename))