在下载之前, 要先获取最终的下载链接.

    path - 一个文件的绝对路径.

    @return red_url, red_url 是重定向后的URL, 如果获取失败,
            就返回原来的dlink;
188510
def get_download_link(cookie, tokens, path):
    '''
    '''
    metas = get_metas(cookie, tokens, path)
    if (not metas or metas.get('errno', -1) != 0 or
            'info' not in metas or len(metas['info']) != 1):
        logger.error('pcs.get_download_link(): %s' % metas)
        return None
    dlink = metas['info'][0]['dlink']
    url = '{0}&cflg={1}'.format(dlink, cookie.get('cflag').value)
    req = net.urlopen_without_redirect(url, headers={
        'Cookie': cookie.sub_output('BAIDUID', 'BDUSS', 'cflag'),
        'Accept': const.ACCEPT_HTML,
    })
    if not req:
        return url
    else:
        return req.getheader('Location', url)
380879
public function path() {
        if ($this->path === null) {
            $rawUrl = $this->rawUrl();

            if (($qsIndex = strpos($rawUrl, '?')) !== false) {
                $this->path = substr($rawUrl, 0, $qsIndex);
            }
            else {
                $this->path = $rawUrl;
            }
        }

        return $this->path;
    }
54442
public static String getDecodedPath(URL url) {
		if (null == url) {
			return null;
		}

		String path = null;
		try {
			// URL对象的getPath方法对于包含中文或空格的问题
			path = URLUtil.toURI(url).getPath();
		} catch (UtilException e) {
			// ignore
		}
		return (null != path) ? path : url.getPath();
	}
1006176
public String getURL()
  {
    if (! isWindows())
      return escapeURL("file:" + getFullPath());

    String path = getFullPath();
    int length = path.length();
    CharBuffer cb = new CharBuffer();

    // #2725, server/1495
    cb.append("file:");

    char ch;
    int offset = 0;
    // For windows, convert /c: to c:
    if (length >= 3
        && path.charAt(0) == '/'
        && path.charAt(2) == ':'
        && ('a' <= (ch = path.charAt(1)) && ch <= 'z'
            || 'A' <= ch && ch <= 'Z')) {
      // offset = 1;
    }
    else if (length >= 3
             && path.charAt(0) == '/'
             && path.charAt(1) == ':'
             && path.charAt(2) == '/') {
      cb.append('/');
      cb.append('/');
      cb.append('/');
      cb.append('/');
      offset = 3;
    }

    for (; offset < length; offset++) {
      ch = path.charAt(offset);

      if (ch == '\\')
        cb.append('/');
      else
        cb.append(ch);
    }

    return escapeURL(cb.toString());

  }
802302
public String getUploadFileUrl(String path) {
        final StringBuilder sb = new StringBuilder(GWT.getModuleBaseURL() + UPLOAD_SERVLET_URL);
        sb.append("?").append("path").append("=").append(URL.encode(path));
        return sb.toString();
    }
1105399
private File getFileFromPath(final String path) {
        File result = (path != null) ? new File(path) : null;
        // AS7-1752 see if a non-existent relative path exists relative to the home dir
        if (result != null && homeDir != null && !result.exists() && !result.isAbsolute()) {
            File relative = new File(homeDir, path);
            if (relative.exists()) {
                result = relative;
            }
        }
        return result;
    }
616007
public String getResourcePath() {
        final StringBuilder sb = new StringBuilder();
        for (final String r : resource)
            sb.append(r + '/');
        return sb.substring(0, Math.max(0, sb.length() - 1));
    }
30817
@Override
    public String getPath() {
        final String fullPath = request.getRequestURI();
        // it shouldn't be null, but in case it is, it's better to return empty string
        if (fullPath == null) {
            return "";
        }
        final String context = request.getContextPath();
        // this one shouldn't be null either, but in case it is, then let's consider it is empty
        if (context != null) {
            return fullPath.substring(context.length());
        }
        return fullPath;
    }
1141355
public UrlPath urlPath() {
        if (null == urlPath) {
            urlPath = UrlPath.of(null == processedUrl ? req().url() : processedUrl);
        }
        return urlPath;
    }
889791
public static File getWebFile(final String path) {
        final ServletContext servletContext = AbstractServletListener.getServletContext();

        File ret;

        try {
            final URL resource = servletContext.getResource(path);
            if (null == resource) {
                return null;
            }

            ret = FileUtils.toFile(resource);

            if (null == ret) {
                final File tempdir = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
                ret = new File(tempdir.getPath() + path);
                FileUtils.copyURLToFile(resource, ret);
                ret.deleteOnExit();
            }

            return ret;
        } catch (final Exception e) {
            LOGGER.log(Level.ERROR, "Reads file [path=" + path + "] failed", e);

            return null;
        }
    }
798765
function getlist(fpath, prefix) {
    try {
      folders = fs.readdirSync(fpath);
    } catch (e) {
      return;
    }

    prefix = prefix || '';

    _.each(folders, function(f) {
      var p;
      npath = path.join(fpath, f);

      // 如果当前f是文件夹，则添加代表文件夹的分隔符，否则判断文件名是否匹配正则，不匹配则不扔进数组
      if (fs.existsSync(npath) && fs.lstatSync(npath).isDirectory()) {

        f += '/';

        // 如果要获取所有文件则递归获取下一层目录的文件
        if (hasGrep) getlist(npath, prefix + f);

      } else if (f.match(re)) {

        p = re ? RegExp.$1 : f;

      } else {
        return;
      }

      // 如果grepKey为string则匹配文件/文件夹名
      if (hasGrep && f.indexOf(grepKey) === -1) return;

      urlList.push({
        name: f,
        path: prefix + (p || f)
      });
    });
  }
403779
private GenericUrl getURL(final String path) {
		final StringBuilder builder = new StringBuilder(getHostname());
		builder.append(path);
		return new GenericUrl(builder.toString());
	}
451128
public String getRawPath() {
    List<String> pathParts = this.pathParts;
    if (pathParts == null) {
      return null;
    }
    StringBuilder buf = new StringBuilder();
    appendRawPathFromParts(buf);
    return buf.toString();
  }
230502
private URL getUrl() {
        ClassLoader loader = null;
        try {
            loader = Thread.currentThread().getContextClassLoader();
        } catch (Exception e) {
            // do nothing
        }

        if (loader == null) {
            loader = ClassPathResource.class.getClassLoader();
        }

        URL url = loader.getResource(this.resourceName);
        if (url == null) {
            // try to check for mis-used starting slash
            // TODO: see TODO below
            if (this.resourceName.startsWith("/")) {
                url = loader.getResource(this.resourceName.replaceFirst("[\\\\/]", ""));
                if (url != null)
                    return url;
            } else {
                // try to add slash, to make clear it's not an issue
                // TODO: change this mechanic to actual path purifier
                url = loader.getResource("/" + this.resourceName);
                if (url != null)
                    return url;
            }
            throw new IllegalStateException("Resource '" + this.resourceName + "' cannot be found.");
        }
        return url;
    }
1098924
public org.apache.hadoop.fs.Path getRawResolvedPath() {
    return new org.apache.hadoop.fs.Path("hdfs://" + hdfs.getHost() + ":"
        + hdfs.getPort() + new String(getResolvedPath()));
  }
1231586
public function path()
    {
        if (is_null($this->path)) {
            $suffix   = $this->config->get('core.url_html_suffix');
            $pathinfo = $this->baseUrl();
            if (false === $suffix) {
                // 禁止伪静态访问
                $this->path = $pathinfo;
            } elseif ($suffix) {
                // 去除正常的URL后缀
                $this->path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i', '', $pathinfo);
            } else {
                // 允许任何后缀访问
                $this->path = preg_replace('/\.' . $this->ext() . '$/i', '', $pathinfo);
            }
        }
        return $this->path;
    }
483794
public static function path()
    {
        $url = '';

        // Get the rest of the URL
        if (!Arr::key('REQUEST_URI', $_SERVER)) {
            // Microsoft IIS doesn't set REQUEST_URI by default
            if ($queryString = Arr::key('QUERY_STRING', $_SERVER, true)) {
                $url .= '?' . $queryString;
            }
        } else {
            $url .= $_SERVER['REQUEST_URI'];
        }

        return $url ?: null;
    }