add support for fetching random matrix and move to using domain names instead of IPs

This commit is contained in:
dymik739 2023-03-16 23:06:26 +02:00
parent 1c70783d22
commit ca37003f32
1 changed files with 19 additions and 3 deletions

View File

@ -9,10 +9,13 @@ import java.net.URL;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
boolean help_enqueued = false; boolean help_enqueued = false;
boolean allow_networking = true; boolean allow_networking = true;
String matrix_file_name = "";
int verbosity = 1; int verbosity = 1;
int p = 0; int p = 0;
@ -31,8 +34,7 @@ public class Main {
p += 2; p += 2;
} }
else { else {
System.err.println("[ERROR] Unknown argument found: " + args[p] + "\n[ERROR] Please, use 'java Main -h' for help"); matrix_file_name = args[p++];
System.exit(1);
} }
} }
catch (Exception e) { catch (Exception e) {
@ -46,6 +48,20 @@ public class Main {
printHelp(allow_networking); printHelp(allow_networking);
System.exit(0); System.exit(0);
} }
if (Objects.equals("", matrix_file_name)) {
System.err.println("[WARN] No filename specified to read from, using default one");
matrix_file_name = "random_matrix.txt";
}
File matrix_file = new File(matrix_file_name);
if (!matrix_file.exists()) {
if (allow_networking) {
System.err.println("[WARN] File is missing, downloading random matrix from the server");
fetchResource("http://lab2.kpi.dev:16554/matrix.py", matrix_file_name);
}
}
} }
private static void fetchResource(String remote_url, String output_filename) { private static void fetchResource(String remote_url, String output_filename) {
@ -71,7 +87,7 @@ public class Main {
System.err.println("[WARN] Help file is missing."); System.err.println("[WARN] Help file is missing.");
if (allow_net) { if (allow_net) {
System.err.println("[INFO] Trying to recover it from the git server"); System.err.println("[INFO] Trying to recover it from the git server");
fetchResource("http://139.162.162.130:3000/dymik739/oop-labs-collection/raw/branch/lab2-dev/labs/2/src/help.txt", "src/help.txt"); fetchResource("http://lab2.kpi.dev:3000/dymik739/oop-labs-collection/raw/branch/lab2-dev/labs/2/src/help.txt", "src/help.txt");
} else { } else {
System.err.println("[INFO] Networking is disabled, not recovering"); System.err.println("[INFO] Networking is disabled, not recovering");
System.exit(1); System.exit(1);