use of com.stanfy.enroscar.rest.request.binary.BinaryData 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.binary.BinaryData in project enroscar by stanfy.
the class PayloadPostConverter method sendRequest.
@Override
public void sendRequest(final URLConnection connection) throws IOException {
ArrayList<BinaryData<?>> binaryData = getRequestDescription().getBinaryData();
if (binaryData != null) {
final BuffersPool buffersPool = BeansManager.get(getContext()).getContainer().getBean(BuffersPool.class);
final OutputStream out = buffersPool.bufferize(connection.getOutputStream());
try {
int size = binaryData.size();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < size; i++) {
binaryData.get(i).writeContentTo(getContext(), out);
}
doSendWorkarounds(UrlConnectionWrapper.unwrap(connection));
} finally {
IoUtils.closeQuietly(out);
}
}
}
Aggregations