-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadManager.java
More file actions
74 lines (51 loc) · 1.61 KB
/
DownloadManager.java
File metadata and controls
74 lines (51 loc) · 1.61 KB
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
import java.net.URL;
import java.util.ArrayList;
public class DownloadManager {
private static DownloadManager sInstance = null;
private static final int DEFAULT_NUM_CONN_PER_DOWNLOAD = 8;
public static final String DEFAULT_OUTPUT_FOLDER = "";
private int mNumConnPerDownload;
private ArrayList<Downloader> mDownloadList;
protected DownloadManager() {
mNumConnPerDownload = DEFAULT_NUM_CONN_PER_DOWNLOAD;
mDownloadList = new ArrayList<Downloader>();
}
public int getNumConnPerDownload() {
return mNumConnPerDownload;
}
public void SetNumConnPerDownload(int value) {
mNumConnPerDownload = value;
}
public Downloader getDownload(int index) {
return mDownloadList.get(index);
}
public void removeDownload(int index) {
mDownloadList.remove(index);
}
public ArrayList<Downloader> getDownloadList() {
return mDownloadList;
}
public Downloader createDownload(URL verifiedURL, String outputFolder) {
HttpDownloader fd = new HttpDownloader(verifiedURL, outputFolder, mNumConnPerDownload);
mDownloadList.add(fd);
return fd;
}
public static DownloadManager getInstance() {
if (sInstance == null)
sInstance = new DownloadManager();
return sInstance;
}
public static URL verifyURL(String fileURL) {
if (!fileURL.toLowerCase().startsWith("http://"))
return null;
URL verifiedUrl = null;
try {
verifiedUrl = new URL(fileURL);
} catch (Exception e) {
return null;
}
if (verifiedUrl.getFile().length() < 2)
return null;
return verifiedUrl;
}
}