Mega Code Archive

 
Categories / Java Book / 006 Networking
 

0361 Relativization

Relativization is the inverse of resolution. URI declares a URI relativize(URI uri) method for relativizing its uri argument against the URI in the current URI object. For any two normalized URI instances u and v, u.relativize(u.resolve(v)).equals(v) and u.resolve(u.relativize(v)).equals(v) evaluate to true. relativize() performs relativization of its URI argument's URI against the URI in the URI object on which this method was called as follows: import java.net.URI; import java.net.URISyntaxException; public class Main { public static void main(String[] args) throws URISyntaxException { URI uri1 = new URI("http://rntsoft.com/"); URI uri2 = new URI("http://rntsoft.com/index.htm"); System.out.println("Relativized URI = " + uri1.relativize(uri2)); } } Output: Relativized URI = index.htm