--- old/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponse.java 2017-08-03 17:42:12.000000000 +0100 +++ new/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponse.java 2017-08-03 17:42:12.000000000 +0100 @@ -39,6 +39,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -270,6 +271,24 @@ return BodyProcessor.asString(charsetFrom(headers)); }; } + /** + * Returns a {@code BodyHandler} which returns {@linkplain + * BodyProcessor#buffering(BodyProcessor,long) buffering BodyProcessors} that + * buffer data before delivering it to the processors created by the given + * {@code downstream} handler. These {@code BodyProcessor} + * instances are created by calling + * {@link BodyProcessor#buffering(BodyProcessor,long) BodyProcessor.buffering()} with + * a processor obtained from the {@code downstream} handler and + * the {@code buffersize} parameter supplied to this call. + * + * @param downstream the downstream handler from the returned handler + * @param buffersize the buffersize parameter passed to {@link BodyProcessor#buffering(BodyProcessor,long) + * BodyProcessor.buffering()} + * @return a body handler + */ + public static BodyHandler buffering(BodyHandler downstream, long buffersize) { + return new BufferingHandler<>(downstream, buffersize); + } /** @@ -403,9 +422,9 @@ * A processor for response bodies. * {@Incubating} *

- * The object acts as a {@link Flow.Subscriber}<{@link ByteBuffer}> to - * the HTTP client implementation which publishes ByteBuffers containing the - * response body. The processor converts the incoming buffers of data to + * The object acts as a {@link Flow.Subscriber}<{@link List}<{@link + * ByteBuffer}>> to the HTTP client implementation which publishes ByteBuffers + * containing the response body. The processor converts the incoming buffers of data to * some user-defined object type {@code T}. *

* The {@link #getBody()} method returns a {@link CompletionStage}{@code } @@ -419,7 +438,7 @@ * @param the response body type */ public interface BodyProcessor - extends Flow.Subscriber { + extends Flow.Subscriber> { /** * Returns a {@code CompletionStage} which when completed will return the @@ -446,6 +465,28 @@ } /** + * Returns a {@code BodyProcessor} which buffers data before delivering + * it to the given downstream processor. The processor guarantees to deliver + * {@code buffersize} bytes of data in each call to {@link #onNext(Object) onNext} + * except for the final call, just before {@link #onComplete() onComplete} + * is called. The final call of {@code onNext} may contain fewer than + * {@code buffersize} + * bytes. + *

+ * The returned processor delegates its {@link #getBody()} call to the + * down stream processor. + * + * @param downstream the downstream processor for the returned handler + * @param buffersize the number of bytes guaranteed to be returned in each + * call to onNext() except for the last call. + * + * @return a body processor + */ + public static BodyProcessor buffering(BodyProcessor downstream, long buffersize) { + return new BufferingProcessor<>(downstream, buffersize); + } + + /** * Returns a {@code BodyProcessor} which stores the response body as a * byte array. *