Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
support input file
Browse files Browse the repository at this point in the history
  • Loading branch information
kasramp committed Aug 10, 2019
1 parent b352b26 commit d52f723
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/CallWayBackMachine.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

/*
* This file is part of InternetWayBackMachine.
* InternetWayBackMachine is free software; you can redistribute it and/or modify
Expand All @@ -22,7 +28,7 @@ public static void main(String[] args)
{
System.out.println("No URL provided!");
}
else
else if(args.length == 1)
{
SubmitUrl su = new SubmitUrl(args[0]);
if(su.getResult())
Expand All @@ -34,10 +40,45 @@ public static void main(String[] args)
System.out.println("Page submission failed :-( ");
}
}
else if(args.length > 1 && "-i".equals(args[0]))
{
processFile(args[1]);
}
else
{
System.out.println("Invalid arguments passed. \n"
+ "Usage:\n"
+ "* java -jar InternetWaybackMachine.jar [URL]\n"
+ "* java -jar InternetWaybackMachine.jar -i [Path to a file contains URLs]");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}

private static void processFile(String filePath)
{
try (BufferedReader reader = Files.newBufferedReader(Paths.get(filePath)))
{
SubmitUrl submitUrl = new SubmitUrl();
reader.lines().forEach(url ->
{
System.out.println(url);
if(submitUrl.getResult(url))
{
System.out.println("Your page submitted sucessfully!");
}
else
{
System.out.println("Page submission failed :-( ");
}
});
}
catch (IOException fileException)
{
System.out.println("Failed to open the file. Make sure it exists");
}
}
}

0 comments on commit d52f723

Please sign in to comment.