|
@@ -30,7 +30,6 @@ import java.io.IOException;
|
30
|
30
|
import java.io.InputStream;
|
31
|
31
|
import java.io.InputStreamReader;
|
32
|
32
|
import java.io.OutputStream;
|
33
|
|
-import java.net.MalformedURLException;
|
34
|
33
|
import java.net.URL;
|
35
|
34
|
import java.net.URLConnection;
|
36
|
35
|
import java.net.URLEncoder;
|
|
@@ -70,14 +69,9 @@ public class Downloader {
|
70
|
69
|
|
71
|
70
|
final URLConnection urlConn = getConnection(url, postData);
|
72
|
71
|
|
73
|
|
- BufferedReader in = null;
|
74
|
|
-
|
75
|
|
- try {
|
76
|
|
- in = new BufferedReader(new InputStreamReader(
|
77
|
|
- urlConn.getInputStream()));
|
78
|
|
-
|
|
72
|
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(
|
|
73
|
+ urlConn.getInputStream()))) {
|
79
|
74
|
String line;
|
80
|
|
-
|
81
|
75
|
do {
|
82
|
76
|
line = in.readLine();
|
83
|
77
|
|
|
@@ -85,8 +79,6 @@ public class Downloader {
|
85
|
79
|
res.add(line);
|
86
|
80
|
}
|
87
|
81
|
} while (line != null);
|
88
|
|
- } finally {
|
89
|
|
- StreamUtils.close(in);
|
90
|
82
|
}
|
91
|
83
|
|
92
|
84
|
return res;
|
|
@@ -140,12 +132,8 @@ public class Downloader {
|
140
|
132
|
final URLConnection urlConn = getConnection(url, "");
|
141
|
133
|
final File myFile = new File(file);
|
142
|
134
|
|
143
|
|
- OutputStream output = null;
|
144
|
|
- InputStream input = null;
|
145
|
|
-
|
146
|
|
- try {
|
147
|
|
- output = new FileOutputStream(myFile);
|
148
|
|
- input = urlConn.getInputStream();
|
|
135
|
+ try (OutputStream output = new FileOutputStream(myFile);
|
|
136
|
+ InputStream input = urlConn.getInputStream()) {
|
149
|
137
|
final int length = urlConn.getContentLength();
|
150
|
138
|
int current = 0;
|
151
|
139
|
|
|
@@ -169,9 +157,6 @@ public class Downloader {
|
169
|
157
|
}
|
170
|
158
|
}
|
171
|
159
|
} while (count > 0);
|
172
|
|
- } finally {
|
173
|
|
- StreamUtils.close(input);
|
174
|
|
- StreamUtils.close(output);
|
175
|
160
|
}
|
176
|
161
|
}
|
177
|
162
|
|
|
@@ -198,14 +183,9 @@ public class Downloader {
|
198
|
183
|
urlConn.setRequestProperty("Content-Type",
|
199
|
184
|
"application/x-www-form-urlencoded");
|
200
|
185
|
|
201
|
|
- DataOutputStream out = null;
|
202
|
|
-
|
203
|
|
- try {
|
204
|
|
- out = new DataOutputStream(urlConn.getOutputStream());
|
|
186
|
+ try (DataOutputStream out = new DataOutputStream(urlConn.getOutputStream())) {
|
205
|
187
|
out.writeBytes(postData);
|
206
|
188
|
out.flush();
|
207
|
|
- } finally {
|
208
|
|
- StreamUtils.close(out);
|
209
|
189
|
}
|
210
|
190
|
}
|
211
|
191
|
|