Gets the content of the specified URI and saves it to a temporary file.
 @param uri [URI, String] the URI to download
 @return [String] the path to the downloaded file
518202
def download_to_temp_file(uri)
      uri = Resync::XML.to_uri(uri)
      @helper.fetch_to_file(uri: uri)
    end
761263
def download
      return io if io.is_a?(Tempfile)

      Tempfile.new(id, binmode: true).tap do |tempfile|
        IO.copy_stream(io, tempfile)
        tempfile.rewind
        tempfile.fsync
      end
    end
1159095
private String encodeUri( String uri ) {
    String newUri = "";
    StringTokenizer st = new StringTokenizer( uri, "/ ", true );
    while ( st.hasMoreTokens()) {
      String tok = st.nextToken();
      if ( tok.equals( "/" ))
        newUri += "/";
      else if ( tok.equals( " " ))
        newUri += "%20";
      else {
        try {
          newUri += URLEncoder.encode( tok, "UTF-8" );
        } catch( UnsupportedEncodingException e ) {
          throw  Log.errRTExcept(e);
        }
      }
    }
    return newUri;
  }
1040337
def uri_read(*args, **kwargs):
    

    with uri_open(*args, **kwargs) as f:
        content = f.read()
    return content
966556
def download_file(self, url):
        
        response = requests.get(url, stream=True)
        response.raise_for_status()
        return (int(response.headers.get('content-length', 0)), response)
335375
def download(style='original', path=nil)
    options = { session: session }
    options[:download_path] = path unless path.nil?
    request = RedboothRuby.request(:download, nil, "files/#{id}/download/#{style}/#{name}", {}, options)
    request.body
  end
218693
def download
      raise "#{@source_url} is not accessible" unless @url.valid?
      f = open(@file_path,'wb')
      count = 0
      @url.net_http.request_get(@url.path) do |r|
        r.read_body do |s|
          @download_length += s.length
          f.write s
          if block_given?
            count += 1
            if count % 100 == 0
              yield @download_length
            end
          end
        end
      end
      f.close
      downloaded = @download_length
      @download_length = 0
      downloaded
    end
857298
def from_uri(uri, options = {}, &block)
      if uri.is_a?(String)
        uri = URI.parse(uri)
        uri = URI.parse("file://#{File.expand_path(uri.to_s)}") if uri.scheme.nil?
      end
      from(uri, options, &block)
    end
179358
def download(url, options = {})
      options = @options.merge(options)

      max_size            = options.delete(:max_size)
      max_redirects       = options.delete(:max_redirects)
      progress_proc       = options.delete(:progress_proc)
      content_length_proc = options.delete(:content_length_proc)
      destination         = options.delete(:destination)
      headers             = options.delete(:headers) || {}

      # Use open-uri's :content_lenth_proc or :progress_proc to raise an
      # exception early if the file is too large.
      #
      # Also disable following redirects, as we'll provide our own
      # implementation that has the ability to limit the number of redirects.
      open_uri_options = {
        content_length_proc: proc { |size|
          if size && max_size && size > max_size
            raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)"
          end
          content_length_proc.call(size) if content_length_proc
        },
        progress_proc: proc { |current_size|
          if max_size && current_size > max_size
            raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)"
          end
          progress_proc.call(current_size) if progress_proc
        },
        redirect: false,
      }

      # Handle basic authentication in the :proxy option.
      if options[:proxy]
        proxy    = URI(options.delete(:proxy))
        user     = proxy.user
        password = proxy.password

        if user || password
          proxy.user     = nil
          proxy.password = nil

          open_uri_options[:proxy_http_basic_authentication] = [proxy.to_s, user, password]
        else
          open_uri_options[:proxy] = proxy.to_s
        end
      end

      open_uri_options.merge!(options)
      open_uri_options.merge!(headers)

      uri = ensure_uri(addressable_normalize(url))

      # Handle basic authentication in the remote URL.
      if uri.user || uri.password
        open_uri_options[:http_basic_authentication] ||= [uri.user, uri.password]
        uri.user = nil
        uri.password = nil
      end

      open_uri_file = open_uri(uri, open_uri_options, follows_remaining: max_redirects)

      # Handle the fact that open-uri returns StringIOs for small files.
      tempfile = ensure_tempfile(open_uri_file, File.extname(open_uri_file.base_uri.path))
      OpenURI::Meta.init tempfile, open_uri_file # add back open-uri methods
      tempfile.extend Down::NetHttp::DownloadedFile

      download_result(tempfile, destination)
    end
252255
def download_file(url, path=None, clobber=False):
    
    if path is None:
        local_filename = os.path.join(directory, url.split('/')[-1])
    else:
        local_filename = path

    if os.path.exists(local_filename) and not clobber:
        logging.info('{} exists; not downloading.'.format(local_filename))
        return local_filename
        
    # NOTE the stream=True parameter
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                #f.flush() commented by recommendation from J.F.Sebastian
    return local_filename
1253233
def get(url)
      begin
        uri = URI.parse(url.strip)
      rescue URI::InvalidURIError
        uri = URI.parse(URI.escape(url.strip))
      end

      # simple hack to read in fixtures instead of url for tests
      fixture = "#{File.dirname(__FILE__)}/../fixtures#{uri.path}"
      File.read(fixture) if File.exist?(fixture)
    end
650940
def download(self, url, file):
        
        if isinstance(file, str) or isinstance(file, unicode):
            file = open(file, 'wb')
        webclient = self.dupe()
        webclient.request('GET', url)
        rsp = webclient.getresponse()
        self._currdl = rsp
        self._dlfile = file
        for chunk in iter(lambda: rsp.read(16384), ''):
            file.write(chunk)
        self._currdl = None
        file.close()
843883
def download(cls, url, filename=None):
        
        return utility.download(url, cls.directory(), filename)
1303529
protected static String getResource(Uri uri) {
        if (!isAPIUri(uri)) {
            return null;
        }

        String scheme = uri.getScheme();
        String apiScheme = getBaseUri().getScheme();

        // Strip out the protocol and store the result in the "remainder" variable
        String remainder = uri.toString().substring(scheme.length());

        // Strip out the protocol from the base URI
        String apiRemainder = getBaseUri().toString().substring(apiScheme.length());

        // Check that the remainder starts with the apiRemainder
        if (!remainder.startsWith(apiRemainder)) {
            return null;
        }

        // Return the path, stripped out of the base uri's path
        return uri.getPath().substring(getBaseUri().getPath().length());
    }
1077273
def parse_uri
      self.uri = URI.parse(raw_url)
      uri.path = "/" if uri.path.empty?
      uri.fragment = nil
      # if this fails, mark the URL as invalid
    rescue
      self.valid = false
    end
1070069
def URI(url) # rubocop:disable Naming/MethodName
      if url.respond_to?(:host)
        url
      elsif url.respond_to?(:to_str)
        default_uri_parser.call(url)
      else
        raise ArgumentError, 'bad argument (expected URI object or URI string)'
      end
    end
397156
def _download_file(uri, bulk_api):
    """"""
    resp = requests.get(uri, headers=bulk_api.headers(), stream=True)
    with tempfile.TemporaryFile("w+b") as f:
        for chunk in resp.iter_content(chunk_size=None):
            f.write(chunk)
        f.seek(0)
        yield f