# HG changeset patch # User Jaroslav Tulach # Date 1380327061 -7200 # Node ID 751852f49324d58e388f52afa73605203390acfc # Parent 6ce019139b13d2d2607a9c52d16d0503950b7e5d Can convert URL to URI diff -r 6ce019139b13 -r 751852f49324 rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java Sat Sep 28 02:04:01 2013 +0200 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java Sat Sep 28 02:11:01 2013 +0200 @@ -18,6 +18,7 @@ package org.apidesign.bck2brwsr.tck; import java.io.InputStream; +import java.net.URL; import org.apidesign.bck2brwsr.vmtest.Compare; import org.apidesign.bck2brwsr.vmtest.VMTest; import org.testng.annotations.Factory; @@ -39,6 +40,11 @@ return sb.toString(); } + @Compare public String toURIFromURL() throws Exception { + URL u = new URL("http://apidesign.org"); + return u.toURI().toString(); + } + @Factory public static Object[] create() { return VMTest.create(ResourcesTest.class); } diff -r 6ce019139b13 -r 751852f49324 rt/emul/mini/src/main/java/java/net/URL.java --- a/rt/emul/mini/src/main/java/java/net/URL.java Sat Sep 28 02:04:01 2013 +0200 +++ b/rt/emul/mini/src/main/java/java/net/URL.java Sat Sep 28 02:11:01 2013 +0200 @@ -920,6 +920,23 @@ } /** + * Returns a {@link java.net.URI} equivalent to this URL. + * This method functions in the same way as new URI (this.toString()). + *

Note, any URL instance that complies with RFC 2396 can be converted + * to a URI. However, some URLs that are not strictly in compliance + * can not be converted to a URI. + * + * @exception URISyntaxException if this URL is not formatted strictly according to + * to RFC2396 and cannot be converted to a URI. + * + * @return a URI instance equivalent to this URL. + * @since 1.5 + */ + public URI toURI() throws URISyntaxException { + return new URI (toString()); + } + + /** * Returns a {@link java.net.URLConnection URLConnection} instance that * represents a connection to the remote object referred to by the * {@code URL}.