|
70 | 70 | * String[] colors = { "blue", "yellow" }; // Ordered collection
|
71 | 71 | * params.put("colors", colors); // url params: "colors[]=blue&colors[]=yellow"
|
72 | 72 | *
|
73 |
| - * List<Map<String, String>> listOfMaps = new ArrayList<Map<String, String>>(); |
| 73 | + * List<Map<String, String>> listOfMaps = new ArrayList<Map<String, |
| 74 | + * String>>(); |
74 | 75 | * Map<String, String> user1 = new HashMap<String, String>();
|
75 | 76 | * user1.put("age", "30");
|
76 | 77 | * user1.put("gender", "male");
|
@@ -181,7 +182,10 @@ public void put(String key, File file) throws FileNotFoundException {
|
181 | 182 | * @throws java.io.FileNotFoundException throws if wrong File argument was passed
|
182 | 183 | */
|
183 | 184 | public void put(String key, File file, String contentType) throws FileNotFoundException {
|
184 |
| - if (key != null && file != null) { |
| 185 | + if (file == null || !file.exists()) { |
| 186 | + throw new FileNotFoundException(); |
| 187 | + } |
| 188 | + if (key != null) { |
185 | 189 | fileParams.put(key, new FileWrapper(file, contentType));
|
186 | 190 | }
|
187 | 191 | }
|
@@ -353,19 +357,19 @@ private HttpEntity createJsonStreamerEntity() throws IOException {
|
353 | 357 | for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
|
354 | 358 | FileWrapper fileWrapper = entry.getValue();
|
355 | 359 | entity.addPart(entry.getKey(),
|
356 |
| - new FileInputStream(fileWrapper.file), |
357 |
| - fileWrapper.file.getName(), |
358 |
| - fileWrapper.contentType); |
| 360 | + new FileInputStream(fileWrapper.file), |
| 361 | + fileWrapper.file.getName(), |
| 362 | + fileWrapper.contentType); |
359 | 363 | }
|
360 | 364 |
|
361 | 365 | // Add stream params
|
362 | 366 | for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
|
363 | 367 | StreamWrapper stream = entry.getValue();
|
364 | 368 | if (stream.inputStream != null) {
|
365 | 369 | entity.addPart(entry.getKey(),
|
366 |
| - stream.inputStream, |
367 |
| - stream.name, |
368 |
| - stream.contentType); |
| 370 | + stream.inputStream, |
| 371 | + stream.name, |
| 372 | + stream.contentType); |
369 | 373 | }
|
370 | 374 | }
|
371 | 375 |
|
|
0 commit comments