11package org .threadly .litesockets .protocols .http .request ;
22
3+ import java .io .InputStream ;
34import java .net .URL ;
45import java .nio .ByteBuffer ;
56import java .nio .charset .Charset ;
1314import java .util .concurrent .TimeUnit ;
1415import java .util .function .Supplier ;
1516
17+ import org .threadly .concurrent .SubmitterExecutor ;
1618import org .threadly .concurrent .future .FutureUtils ;
1719import org .threadly .concurrent .future .ListenableFuture ;
1820import org .threadly .litesockets .protocols .http .shared .HTTPAddress ;
@@ -270,6 +272,11 @@ public HTTPRequestBuilder setBody(final ByteBuffer bb) {
270272 return this ;
271273 }
272274
275+ public HTTPRequestBuilder setStreamedBody (final SubmitterExecutor executor , final int bodySize ,
276+ final InputStream bodyStream ) {
277+ return setStreamedBody (bodySize , bodyProducer (executor , bodyStream ));
278+ }
279+
273280 public HTTPRequestBuilder setStreamedBody (final int bodySize ,
274281 final Supplier <ListenableFuture <ByteBuffer >> bodySupplier ) {
275282 this .bodySupplier = bodySupplier ;
@@ -278,6 +285,24 @@ public HTTPRequestBuilder setStreamedBody(final int bodySize,
278285 return this ;
279286 }
280287
288+ public HTTPRequestBuilder setChunkedBody (final SubmitterExecutor executor ,
289+ final InputStream bodyStream ) {
290+ return setChunkedBody (bodyProducer (executor , bodyStream ));
291+ }
292+
293+ private Supplier <ListenableFuture <ByteBuffer >> bodyProducer (final SubmitterExecutor executor ,
294+ final InputStream bodyStream ) {
295+ return () -> executor .submit (() -> {
296+ byte [] buffer = new byte [8192 ];
297+ int c = bodyStream .read (buffer );
298+ if (c > 0 ) {
299+ return ByteBuffer .wrap (buffer , 0 , c );
300+ } else {
301+ return null ;
302+ }
303+ });
304+ }
305+
281306 public HTTPRequestBuilder setChunkedBody (final Supplier <ListenableFuture <ByteBuffer >> bodySupplier ) {
282307 this .bodySupplier = bodySupplier ;
283308 this .removeHeader (HTTPConstants .HTTP_KEY_CONTENT_LENGTH );
0 commit comments