-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTester.java
89 lines (73 loc) · 3.05 KB
/
Tester.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Tester {
public static void main(String[] args) throws MalformedURLException {
String[] links = {"http://centos.activecloud.co.il/6.10/isos/x86_64/CentOS-6.10-x86_64-netinstall.iso"};
// //check if CMD will run
// String[] links2 = {"http://centos.activecloud.co.il\\6.10\\isos\\x86_64\\CentOS-6.10-x86_64-netinstall.iso"};
// //FileWriter writer = new FileWriter();
// System.out.println();
// System.out.println(writer.fileName);
String fileName = txtParser(links[0]);
//String strUrl = "http://centos.activecloud.co.il/6.10/isos/x86_64/CentOS-6.10-x86_64-netinstall.iso";
/*
String strUrl = "https://download.sketchapp.com/sketch-61.2-89653.zip?_ga=2.137558832.1675698364.1578132420-1989857718.1564751276";
URL url = new URL(strUrl);
System.out.println(getFileSize(url));
String byteRange = "bytes=" + 0 + "-" + 24;
System.out.println(byteRange);
*/
// String[] arr = IdcDm.listFromFile("/home/PointBlank/Documents/linksTest");
// printArray(arr);
// MetaData data = new MetaData(1, links);
// data.serialize();
// data.setFileSize();
// data = MetaData.deserialize();
// System.out.println(data.getFileSize());
// MetaData.deleteFile("temp23f3sersdf.ser");
String url = "https://archive.org/download/Mario1_500/Mario1_500.avi";
}
public static String txtParser(String link) {
String fileName = "";
if (link.contains("\\")) { //if we are dealing with blackslashes
String newLink = link.replace('\\', '/');
fileName = newLink.substring(newLink.lastIndexOf('/')+1, newLink.length());
}
else { //if we are dealing with forward slashes
fileName = link.substring(link.lastIndexOf('/') + 1, link.length());
}
//String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.'));
//return fileNameWithoutExtension;
System.out.println(fileName);
return fileName;
}
public static void printArray(String[] arr){
System.out.println("printing -------");
for (int i=0; i<arr.length; i++){
System.out.println( arr[i]);
}
}
//using a HEAD request to get the file size
/* private static int getFileSize(URL url) throws MalformedURLException {
URLConnection conn = null;
try {
conn = url.openConnection();
if(conn instanceof HttpURLConnection) {
((HttpURLConnection)conn).setRequestMethod("HEAD");
}
conn.getInputStream();
return conn.getContentLength();
}
catch (IOException e) {
throw new RuntimeException(e);
}
finally {
if(conn instanceof HttpURLConnection) {
((HttpURLConnection)conn).disconnect();
}
}
}*/
}