Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不透明URI和分层URI之间的区别?_Java_Uri - Fatal编程技术网

Java 不透明URI和分层URI之间的区别?

Java 不透明URI和分层URI之间的区别?,java,uri,Java,Uri,在java网络的上下文中,不透明和层次URI之间有什么区别?这是由URI类的 当且仅当URI是绝对的且其特定于方案的部分不以斜杠字符('/')开头时,URI是不透明的。不透明URI有一个方案、特定于方案的部分,可能还有一个片段;所有其他组件都未定义。 它所指的“组件”是由各种URIgetter返回的值 除此之外,“差异”包括根据相关规范不透明和分层URI之间的固有差异;e、 g 这些差异决不是Java特有的。不透明uri的典型示例是邮件到urlmailto:a@b.com。它们不同于层次u

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

这是由URI类的

当且仅当URI是绝对的且其特定于方案的部分不以斜杠字符('/')开头时,URI是不透明的。不透明URI有一个方案、特定于方案的部分,可能还有一个片段;所有其他组件都未定义。

它所指的“组件”是由各种
URI
getter返回的值

除此之外,“差异”包括根据相关规范不透明和分层URI之间的固有差异;e、 g


这些差异决不是Java特有的。

不透明uri的典型示例是邮件到url
mailto:a@b.com
。它们不同于层次uri,因为它们不描述资源的路径

因此,对于
getPath
,不透明的Uri返回
null

一些例子:

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]