+ int redirects = 5;
+ System.out.println("Download: Need to download: " + urls[t]);
+ HttpURLConnection conn = (HttpURLConnection) urls[t].openConnection();
+ String auth = "Basic " + Base64.getEncoder().encodeToString(urls[t].getUserInfo().getBytes());
+ long fileLength = 0L;
+
+ while (redirects > 0) {
+ redirects--;
+
+ conn.setRequestProperty("User-Agent", "GpsPrune v" + GpsPrune.VERSION_NUMBER);
+ conn.setRequestProperty("Authorization", auth);
+ conn.setInstanceFollowRedirects(false);
+ conn.setUseCaches(false);
+
+ int status = conn.getResponseCode();
+ if (status == 200)
+ {
+ inStream = conn.getInputStream();
+ fileLength = conn.getContentLengthLong();
+ break;
+ }
+ else if (status == 302)
+ {
+ // redirected to SSO server then back to original resource
+ String newUrl = conn.getHeaderField("Location");
+ conn = (HttpURLConnection) (new URL(newUrl)).openConnection();
+ }
+ else
+ {
+ throw new IOException("Invalid response from server: " +status+conn.getContent());
+ }
+ }
+ _progress.setValue(t * 10 + 1);