Skip to content

Commit 816578f

Browse files
committed
Throwing exception to fill expectations
1 parent 93e194a commit 816578f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

library/src/main/java/com/loopj/android/http/RequestParams.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
* String[] colors = { "blue", "yellow" }; // Ordered collection
7171
* params.put("colors", colors); // url params: "colors[]=blue&colors[]=yellow"
7272
*
73-
* List<Map<String, String>> listOfMaps = new ArrayList<Map<String, String>>();
73+
* List<Map<String, String>> listOfMaps = new ArrayList<Map<String,
74+
* String>>();
7475
* Map<String, String> user1 = new HashMap<String, String>();
7576
* user1.put("age", "30");
7677
* user1.put("gender", "male");
@@ -181,7 +182,10 @@ public void put(String key, File file) throws FileNotFoundException {
181182
* @throws java.io.FileNotFoundException throws if wrong File argument was passed
182183
*/
183184
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) {
185189
fileParams.put(key, new FileWrapper(file, contentType));
186190
}
187191
}
@@ -353,19 +357,19 @@ private HttpEntity createJsonStreamerEntity() throws IOException {
353357
for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
354358
FileWrapper fileWrapper = entry.getValue();
355359
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);
359363
}
360364

361365
// Add stream params
362366
for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
363367
StreamWrapper stream = entry.getValue();
364368
if (stream.inputStream != null) {
365369
entity.addPart(entry.getKey(),
366-
stream.inputStream,
367-
stream.name,
368-
stream.contentType);
370+
stream.inputStream,
371+
stream.name,
372+
stream.contentType);
369373
}
370374
}
371375

0 commit comments

Comments
 (0)