URIUtilsHC4.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:remote-files-sync 作者:
/**
 * A convenience method that creates a new {@link URI} whose scheme, host, port, path,
 * query are taken from the existing URI, dropping any fragment or user-information.
 * The path is set to "/" if not explicitly specified. The existing URI is returned
 * unmodified if it has no fragment or user-information and has a path.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 */
public static URI rewriteURI(final URI uri) throws URISyntaxException {
    Args.notNull(uri, "URI");
    if (uri.isOpaque()) {
        return uri;
    }
    final URIBuilder uribuilder = new URIBuilder(uri);
    if (uribuilder.getUserInfo() != null) {
        uribuilder.setUserInfo(null);
    }
    if (TextUtils.isEmpty(uribuilder.getPath())) {
        uribuilder.setPath("/");
    }
    if (uribuilder.getHost() != null) {
        uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ENGLISH));
    }
    uribuilder.setFragment(null);
    return uribuilder.build();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号