当前位置: 首页>>代码示例>>Java>>正文


Java URI.normalize方法代码示例

本文整理汇总了Java中java.net.URI.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java URI.normalize方法的具体用法?Java URI.normalize怎么用?Java URI.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URI的用法示例。


在下文中一共展示了URI.normalize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: normalizeUrl

import java.net.URI; //导入方法依赖的package包/类
/**
 * Some basic sanitization of URLs, so that two URLs which have the same semantic meaning
 * are represented by the exact same string by F-Droid. This will help to make sure that,
 * e.g. "http://10.0.1.50" and "http://10.0.1.50/" are not two different repositories.
 * <p>
 * Currently it normalizes the path so that "/./" are removed and "test/../" is collapsed.
 * This is done using {@link URI#normalize()}. It also removes multiple consecutive forward
 * slashes in the path and replaces them with one. Finally, it removes trailing slashes.
 */
private String normalizeUrl(String urlString) throws URISyntaxException {
    if (urlString == null) {
        return null;
    }
    URI uri = new URI(urlString);
    if (!uri.isAbsolute()) {
        throw new URISyntaxException(urlString, "Must provide an absolute URI for repositories");
    }

    uri = uri.normalize();
    String path = uri.getPath();
    if (path != null) {
        path = path.replaceAll("//*/", "/"); // Collapse multiple forward slashes into 1.
        if (path.length() > 0 && path.charAt(path.length() - 1) == '/') {
            path = path.substring(0, path.length() - 1);
        }
    }

    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
            path, uri.getQuery(), uri.getFragment()).toString();
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:31,代码来源:ManageReposActivity.java

示例2: b

import java.net.URI; //导入方法依赖的package包/类
public static String b(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    URI i = i(str);
    if (i == null) {
        return str;
    }
    i = i.normalize();
    if (i.isOpaque()) {
        return str;
    }
    i = a(i.getScheme(), i.getAuthority(), "/", null, null);
    if (i != null) {
        return i.toString();
    }
    return str;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:jr.java

示例3: c

import java.net.URI; //导入方法依赖的package包/类
public static String c(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    URI i = i(str);
    if (i == null) {
        return str;
    }
    i = i.normalize();
    if (i.isOpaque()) {
        return str;
    }
    i = URIUtils.resolve(i, "./");
    if (i != null) {
        return i.toString();
    }
    return str;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:jr.java

示例4: normalize

import java.net.URI; //导入方法依赖的package包/类
public static Optional<URI> normalize(@Nonnull URI uri) {
  URI n = uri.normalize();
  String host = stripWWW(n);
  host = host == null ? null : host.toLowerCase();
  String path = normalizePath(n).getPath();
  try {
    if (n.isOpaque()) {
      return Optional.of(new URI(n.getScheme(), n.getSchemeSpecificPart(), n.getFragment()));
    } else {
      return Optional.of(new URI(n.getScheme(), null, host, n.getPort(), path, null, null));
    }
  } catch (URISyntaxException e) {
    // unlikely deviation
    throw new RuntimeException(e);
  }
}
 
开发者ID:EHRI,项目名称:rs-aggregator,代码行数:17,代码来源:NormURI.java

示例5: testSlashifyUNCPath

import java.net.URI; //导入方法依赖的package包/类
public void testSlashifyUNCPath() throws Exception {
    String unc = "\\\\192.168.0.201\\data\\services\\web\\com_resource\\";
    URI uri = FileBasedURLMapper.toURI(unc, true, '\\');
    final URI norm = uri.normalize();

    assertTrue("Is normalized: " + uri + " == " + norm, uri.equals(norm));
    assertEquals("192.168.0.201", uri.getHost());
    assertEquals("/data/services/web/com_resource/", uri.getPath());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:FileBasedURLMapperTest.java

示例6: match

import java.net.URI; //导入方法依赖的package包/类
public static boolean match(URIPattern[] patterns, URI uri) {
    URI normalized = uri.normalize();
    for (URIPattern pattern : patterns) {
        if (pattern.matchNormalized(normalized)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:URIPattern.java

示例7: Path

import java.net.URI; //导入方法依赖的package包/类
/**
 * Construct a path from a URI
 */
public Path(URI aUri) {
  uri = aUri.normalize();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:7,代码来源:Path.java

示例8: create

import java.net.URI; //导入方法依赖的package包/类
public static WebmateEnvironment create(URI baseUri) {
    return new WebmateEnvironment(baseUri.normalize());
}
 
开发者ID:webmate-io,项目名称:webmate-sdk-java,代码行数:4,代码来源:WebmateEnvironment.java


注:本文中的java.net.URI.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。