當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。