Here you can find the source of getURLForward(URL url)
public static URL getURLForward(URL url) throws Exception
//package com.java2s; //License from project: Apache License import java.net.URL; import java.net.URLConnection; public class Main { public static URL getURLForward(URL url) throws Exception { URLConnection con = url.openConnection(); String location = con.getHeaderField("Location"); if (location != null) { return new URL(location); }//from ww w.j a va 2 s .c om return url; } }