if (entityProcessing == RequestEntityProcessing.BUFFERED) {
byte[] entityBytes = bufferEntity(requestContext);
builder = builder.setBody(entityBytes);
} else if (entityProcessing == RequestEntityProcessing.CHUNKED) {
final FeedableBodyGenerator bodyGenerator = new FeedableBodyGenerator();
final Integer chunkSize = requestContext.resolveProperty(ClientProperties.CHUNKED_ENCODING_SIZE, 0);
if (chunkSize > 0) {
bodyGenerator.setMaxPendingBytes(chunkSize);
}
final FeedableBodyGenerator.Feeder feeder = new FeedableBodyGenerator.SimpleFeeder(bodyGenerator) {
@Override
public void flush() throws IOException {
requestContext.writeEntity();
}
};
requestContext.setStreamProvider(new OutboundMessageContext.StreamProvider() {
@Override
public OutputStream getOutputStream(int contentLength) throws IOException {
return new FeederAdapter(feeder);
}
});
bodyGenerator.setFeeder(feeder);
builder.setBody(bodyGenerator);
} else {
builder.setBody(getEntityWriter(requestContext));
}
}