Skip to content

Commit

Permalink
tweaks to http in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
not-coded committed Mar 26, 2024
1 parent b473234 commit 58bca18
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/com/nexia/installer/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class Utils {

public static final DateFormat ISO_8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

public static String userAgent = "Mozilla/5.0 (compatible; combat-test-installer; +https://github.com/nexia-cts/combat-test-installer)";

public static void extractZip(Path file, Path path) throws IOException {
ZipInputStream zipIn = new ZipInputStream(Files.newInputStream(Paths.get(file.toString())));
ZipEntry entry = zipIn.getNextEntry();
Expand Down Expand Up @@ -56,7 +58,7 @@ public static void writeToFile(Path path, String string) throws IOException {
Files.write(path, string.getBytes(StandardCharsets.UTF_8));
}

public static void downloadFile(URL url, Path path) throws IOException {
public static void downloadFile(URL url, Path path) {
try (InputStream in = openUrl(url)) {
Files.createDirectories(path.getParent());
Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING);
Expand All @@ -67,7 +69,8 @@ public static void downloadFile(URL url, Path path) throws IOException {
t.addSuppressed(t2);
}

throw t;
InstallerUtils.showError(t.getMessage());
t.printStackTrace();
}
}

Expand All @@ -76,6 +79,7 @@ public static void downloadFile(URL url, Path path) throws IOException {
private static InputStream openUrl(URL url) throws IOException {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestProperty("User-Agent", userAgent);
conn.setConnectTimeout(HTTP_TIMEOUT_MS);
conn.setReadTimeout(HTTP_TIMEOUT_MS);
conn.connect();
Expand Down

0 comments on commit 58bca18

Please sign in to comment.