Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
The MIT License
Copyright (c) 2013 Mashape (http://mashape.com)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.mashape.unirest.request.body;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import com.mashape.unirest.http.utils.MapUtil;
import com.mashape.unirest.request.BaseRequest;
import com.mashape.unirest.request.HttpRequest;
public class MultipartBody extends BaseRequest implements Body {
// MultipartFile should be kept adding order
private List keyOrder = new ArrayList();
private Map> parameters = new LinkedHashMap>();
private Map contentTypes = new HashMap();
private boolean hasFile;
private HttpRequest httpRequestObj;
private HttpMultipartMode mode;
public MultipartBody(HttpRequest httpRequest) {
super(httpRequest);
this.httpRequestObj = httpRequest;
}
public MultipartBody field(String name, String value) {
return field(name, value, false, null);
}
public MultipartBody field(String name, String value, String contentType) {
return field(name, value, false, contentType);
}
public MultipartBody field(String name, Collection> collection) {
for(Object current : collection) {
boolean isFile = current instanceof File;
field(name, current, isFile, null);
}
return this;
}
public MultipartBody field(String name, Object value) {
return field(name, value, false, null);
}
public MultipartBody field(String name, Object value, boolean file) {
return field(name, value, file, null);
}
public MultipartBody field(String name, Object value, boolean file, String contentType) {
if (!keyOrder.contains(name)) keyOrder.add(name);
List