add support for fetching random matrix and move to using domain names instead of IPs
This commit is contained in:
		
							parent
							
								
									1c70783d22
								
							
						
					
					
						commit
						ca37003f32
					
				@ -9,10 +9,13 @@ import java.net.URL;
 | 
			
		||||
import java.io.BufferedInputStream;
 | 
			
		||||
import java.io.FileOutputStream;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class Main {
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        boolean help_enqueued = false;
 | 
			
		||||
        boolean allow_networking = true;
 | 
			
		||||
        String matrix_file_name = "";
 | 
			
		||||
        int verbosity = 1;
 | 
			
		||||
        
 | 
			
		||||
        int p = 0;
 | 
			
		||||
@ -31,8 +34,7 @@ public class Main {
 | 
			
		||||
                    p += 2;
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    System.err.println("[ERROR] Unknown argument found: " + args[p] + "\n[ERROR] Please, use 'java Main -h' for help");
 | 
			
		||||
                    System.exit(1);
 | 
			
		||||
                    matrix_file_name = args[p++];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {
 | 
			
		||||
@ -46,6 +48,20 @@ public class Main {
 | 
			
		||||
            printHelp(allow_networking);
 | 
			
		||||
            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) {
 | 
			
		||||
@ -71,7 +87,7 @@ public class Main {
 | 
			
		||||
                System.err.println("[WARN] Help file is missing.");
 | 
			
		||||
                if (allow_net) {
 | 
			
		||||
                    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 {
 | 
			
		||||
                    System.err.println("[INFO] Networking is disabled, not recovering");
 | 
			
		||||
                    System.exit(1);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user