final ExecutorDelivery delivery = new ExecutorDelivery(new Handler(Looper.getMainLooper()));
setLoadingListener(loadingListener);
if (loadingListener != null) {
mMultipartEntity.setListener(new ProgressListener() {
long time = SystemClock.uptimeMillis();
long count = -1;
@Override
public void transferred(long num) {
if (count == -1) {
count = mMultipartEntity.getContentLength();
}
// LogUtils.d("bacy", "upload->" + count + ",num->" + num);
long thisTime = SystemClock.uptimeMillis();
if (thisTime - time >= getRate() || count == num) {
time = thisTime;
delivery.postLoading(MultiPartRequest.this, count, num);
}
}
});
}
setRetryPolicy(new DefaultRetryPolicy(TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
}
@Override
public String getBodyContentType() {
return mMultipartEntity.getContentType().getValue();
}
public void writeTo(final OutputStream out) throws IOException {
if (out == null) {
throw new IllegalArgumentException("Output stream may not be null"); //$NON-NLS-1$
}
for (Part part : parts) {
part.writeTo(out, boundary);
}
out.write(boundary.getClosingBoundary());
out.flush();
}