use of com.stanfy.enroscar.rest.request.net.multipart.StringPart in project enroscar by stanfy.
the class UploadPostConverter method composeParts.
/**
* @param context application context
* @param requestDescription request description
* @return upload request parts obtained from the request description
* @throws IOException if an I/O error happens
*/
protected static Part[] composeParts(final Context context, final RequestDescription requestDescription) throws IOException {
final ArrayList<BinaryData<?>> binaryData = requestDescription.getBinaryData();
final List<Parameter> params = requestDescription.getSimpleParameters().getChildren();
int realCount = 0;
final int binaryCount = binaryData != null ? binaryData.size() : 0;
Part[] parts = new Part[params.size() + binaryCount];
for (final Parameter p : params) {
if (p instanceof ParameterValue) {
final ParameterValue pv = (ParameterValue) p;
if (pv.getValue() == null) {
continue;
}
parts[realCount++] = new StringPart(pv.getName(), pv.getValue(), requestDescription.getEncoding().name());
}
}
for (int i = 0; i < binaryCount; i++) {
final Part part = binaryData.get(i).createHttpPart(context);
if (part != null) {
parts[realCount++] = part;
}
}
if (realCount < parts.length) {
final Part[] trim = new Part[realCount];
System.arraycopy(parts, 0, trim, 0, realCount);
parts = trim;
}
return parts;
}
use of com.stanfy.enroscar.rest.request.net.multipart.StringPart in project enroscar by stanfy.
the class StringBinaryData method createHttpPart.
@Override
public Part createHttpPart(final Context context) throws IOException {
StringPart sp = new StringPart("", str, IoUtils.UTF_8_NAME);
sp.setContentType(getContentType());
return sp;
}
Aggregations