本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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());
}
示例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;
}
示例7: Path
import java.net.URI; //导入方法依赖的package包/类
/**
* Construct a path from a URI
*/
public Path(URI aUri) {
uri = aUri.normalize();
}
示例8: create
import java.net.URI; //导入方法依赖的package包/类
public static WebmateEnvironment create(URI baseUri) {
return new WebmateEnvironment(baseUri.normalize());
}