不透明和分层 URI 之间的区别? [英] Difference between opaque and hierarchical URI?

查看:40
本文介绍了不透明和分层 URI 之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java 网络 上下文中不透明分层URI 之间的区别是什么?

What is the Difference between opaque and hierarchical URI in context of java networking ?

推荐答案

不透明 uri 的典型示例是邮件到 url mailto:a@b.com.它们与分层 uri 的不同之处在于它们不描述资源的路径.

A typical example of an opaque uri is a mail to url mailto:a@b.com. They differ from a hierarchical uri in that they don't describe a path to a resource.

因此,不透明的 Uri 为 getPath 返回 null.

Therefore a Uri that is opaque returns null for getPath.

一些例子:

public static void main(String[] args) {
    printUriInfo(URI.create("mailto:a@b.com"));
    printUriInfo(URI.create("http://example.com"));
    printUriInfo(URI.create("http://example.com/path"));
    printUriInfo(URI.create("scheme://example.com"));
    printUriInfo(URI.create("scheme:example.com"));
    printUriInfo(URI.create("scheme:example.com/path"));
    printUriInfo(URI.create("path"));
    printUriInfo(URI.create("/path"));
}

private static void printUriInfo(URI uri) {
    System.out.println(String.format("Uri [%s]", uri));
    System.out.println(String.format(" is %sopaque", uri.isOpaque() ? "" : "not "));
    System.out.println(String.format(" is %sabsolute", uri.isAbsolute() ? "" : "not "));
    System.out.println(String.format(" Path [%s]", uri.getPath()));
}

打印:

Uri [mailto:a@b.com]
 is opaque
 is absolute
 Path [null]
Uri [http://example.com]
 is not opaque
 is absolute
 Path []
Uri [http://example.com/path]
 is not opaque
 is absolute
 Path [/path]
Uri [scheme://example.com]
 is not opaque
 is absolute
 Path []
Uri [scheme:example.com]
 is opaque
 is absolute
 Path [null]
Uri [scheme:example.com/path]
 is opaque
 is absolute
 Path [null]
Uri [path]
 is not opaque
 is not absolute
 Path [path]
Uri [/path]
 is not opaque
 is not absolute
 Path [/path]

这篇关于不透明和分层 URI 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆