private URL resolveRedirects(URL url, int redirectCount) throws IOException {
URLConnection uc = url.openConnection();
if (uc instanceof HttpURLConnection) {
HttpURLConnection huc = (HttpURLConnection)uc;
huc.setInstanceFollowRedirects(false);
huc.connect();
int responseCode = huc.getResponseCode();
String location = huc.getHeaderField("location");
huc.disconnect();
if ((responseCode == HttpURLConnection.HTTP_MOVED_TEMP) && (redirectCount < 5)) {
//System.out.println(responseCode);