@@ -25,37 +25,38 @@ public class DownloadFile extends Base<Map<String, String>> {
25
25
private Configuration configuration ;
26
26
private HttpDownloader downloader ;
27
27
28
- public DownloadFile (Configuration configuration , String protocol , String domain , String urlIndex , String host , int [] range ,
29
- String suffixOrQuery , String addPrefix , String rmPrefix , String downPath , String savePath , int saveIndex )
30
- throws IOException {
28
+ public DownloadFile (Configuration configuration , String protocol , String domain , String urlIndex , String host ,
29
+ int [] range , String suffixOrQuery , String addPrefix , String rmPrefix , String downPath , String savePath ,
30
+ int saveIndex ) throws IOException {
31
31
super ("download" , "" , "" , null , savePath , saveIndex );
32
32
set (configuration , protocol , domain , urlIndex , host , range , suffixOrQuery , addPrefix , rmPrefix , downPath );
33
33
downloader = new HttpDownloader (configuration );
34
34
}
35
35
36
- public DownloadFile (Configuration configuration , String protocol , String domain , String urlIndex , String host , int [] range ,
37
- String suffixOrQuery , String addPrefix , String rmPrefix , String downPath ) throws IOException {
36
+ public DownloadFile (Configuration configuration , String protocol , String domain , String urlIndex , String host ,
37
+ int [] range , String suffixOrQuery , String addPrefix , String rmPrefix , String downPath ) throws IOException {
38
38
super ("download" , "" , "" , null );
39
39
set (configuration , protocol , domain , urlIndex , host , range , suffixOrQuery , addPrefix , rmPrefix , downPath );
40
40
downloader = new HttpDownloader (configuration );
41
41
}
42
42
43
43
public DownloadFile (Configuration configuration , String protocol , String domain , String urlIndex , String host ,
44
- int [] range , String suffixOrQuery , String addPrefix , String rmPrefix ,
45
- String downPath , String savePath ) throws IOException {
46
- this (configuration , protocol , domain , urlIndex , host , range , suffixOrQuery , addPrefix , rmPrefix ,
47
- downPath , savePath , 0 );
44
+ int [] range , String suffixOrQuery , String addPrefix , String rmPrefix , String downPath , String savePath )
45
+ throws IOException {
46
+ this (configuration , protocol , domain , urlIndex , host , range , suffixOrQuery , addPrefix , rmPrefix , downPath ,
47
+ savePath , 0 );
48
48
}
49
49
50
- private void set (Configuration configuration , String protocol , String domain , String urlIndex , String host , int [] range ,
51
- String suffixOrQuery , String addPrefix , String rmPrefix , String downPath ) throws IOException {
50
+ private void set (Configuration configuration , String protocol , String domain , String urlIndex , String host ,
51
+ int [] range , String suffixOrQuery , String addPrefix , String rmPrefix , String downPath ) throws IOException {
52
52
this .configuration = configuration ;
53
53
if (domain == null || "" .equals (domain )) {
54
54
if (urlIndex == null || "" .equals (urlIndex )) {
55
55
throw new IOException ("please set one of domain and url-index." );
56
56
} else {
57
57
this .urlIndex = urlIndex ;
58
58
}
59
+ this .domain = null ;
59
60
} else {
60
61
this .protocol = protocol == null || !protocol .matches ("(http|https)" ) ? "http" : protocol ;
61
62
RequestUtils .lookUpFirstIpFromHost (domain );
@@ -79,8 +80,10 @@ private void set(Configuration configuration, String protocol, String domain, St
79
80
this .preDown = true ;
80
81
} else {
81
82
File file = new File (downPath );
82
- if (file .exists () && !file .isDirectory ()) {
83
- throw new IOException ("please change down-path because it's existed file." );
83
+ if (file .exists ()) {
84
+ if (!file .isDirectory ()) throw new IOException ("please change down-path because it's existed file." );
85
+ } else if (!file .mkdirs ()) {
86
+ if (!file .mkdirs ()) throw new IOException (String .join ("" , "directory: " , downPath , " can not be created." ));
84
87
}
85
88
}
86
89
}
@@ -108,8 +111,7 @@ protected String singleResult(Map<String, String> line) throws Exception {
108
111
url = url + suffixOrQuery ;
109
112
} else {
110
113
if (key == null || "" .equals (key )) throw new IOException ("key is not exists or empty in " + line );
111
- url = String .join ("" , protocol , "://" , domain , "/" ,
112
- key .replace ("\\ ?" , "%3f" ), suffixOrQuery );
114
+ url = String .join ("" , protocol , "://" , domain , "/" , key .replace ("\\ ?" , "%3f" ), suffixOrQuery );
113
115
key = String .join ("" , addPrefix , FileUtils .rmPrefix (rmPrefix , key )); // 目标文件名
114
116
}
115
117
if (preDown ) {
0 commit comments