A typical example of an opaque uri is the mailto: a@b.com URL mailto: a@b.com . They differ from the hierarchical uri in that they do not describe the path to the resource.
Therefore, an opaque Uri returns null for getPath .
Some examples:
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())); }
Print
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]
source share