It is suggested in the docs to not to use InputStream in setBody, because in order to get the content length, the library will need to load everything in memory.
And it seems that ByteArrayBodyGenerator has the same issue. To get the content length it uses a call to bytes.length() and bytes is your byte array (private final byte[] bytes;). So, to get the length of a byte array, the array needs to be loaded in memory.
Here is the source from github:
https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/generators/ByteArrayBodyGenerator.java
You may write your own BodyGenerator implementation to avoid the issue.
Also you asked for an example of using BodyGenerator:
final SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder()
.setRequestTimeoutInMs(Integer.MAX_VALUE)
.setUrl(url)
.build();
client.post(new ByteArrayBodyGenerator(YOUR_BYTE_ARRAY)).get();
And if you want to use legacy API:
final AsyncHttpClientConfig config
= new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(Integer.MAX_VALUE).build();
final AsyncHttpClient client = new AsyncHttpClient(config);
client.preparePost(url)
.setBody(new ByteArrayBodyGenerator(YOUR_BYTE_ARRAY))
.execute()
.get();