MultipartFormEntity buildEntity() {
final String st = subType != null ? subType : DEFAULT_SUBTYPE;
final Charset cs = charset;
final String b = boundary != null ? boundary : generateBoundary();
final List<FormBodyPart> bps = bodyParts != null ? new ArrayList<FormBodyPart>(bodyParts) :
Collections.<FormBodyPart>emptyList();
final HttpMultipartMode m = mode != null ? mode : HttpMultipartMode.STRICT;
final AbstractMultipartForm form;
switch (m) {
case BROWSER_COMPATIBLE:
form = new HttpBrowserCompatibleMultipart(st, cs, b, bps);
break;
case RFC6532:
form = new HttpRFC6532Multipart(st, cs, b, bps);
break;
default:
form = new HttpStrictMultipart(st, cs, b, bps);
}
return new MultipartFormEntity(form, generateContentType(b, cs), form.getTotalLength());
}