本文整理匯總了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());
}