This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd0wnloader.java
47 lines (43 loc) · 1.71 KB
/
d0wnloader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class d0wnloader {
private static JFrame temp;
public static void download(String url, String out) throws IOException {
System.out.println("DL "+url+" "+out);
URL website;
try {
website = new URL(url);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(new File(out));
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE );
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println("Internet error, press enter to proceed");
JOptionPane.showMessageDialog(temp , "Failed to download file due to a network error. Here's your debug data "+e.getMessage());
(new PrintWriter(new FileWriter("Warning_Download_Failed.warning"))).close();
}
}
public static void main(String[] args) throws Exception{
String repoBase = "https://raw.githubusercontent.com/"; // Need slash
String repoEnd = "javaarchive/java-tools/master/"; // username/repo-name/branch/
String u = repoBase + repoEnd;
temp = new JFrame("Download...");
download(u + "javatools.java","javatools.java");
download(u + "jt.java","jt.java");
download(u + "compilestandard.java","compilestandard.java");
JOptionPane.showMessageDialog(temp , "Downloader is done!");
temp.dispose();
}
}