RFR 8184285: Buffer sizes of Flow based BodyProcessor API
Michael McMahon
michael.x.mcmahon at oracle.com
Thu Aug 3 17:02:23 UTC 2017
Hi,
The HTTP client work is continuing in a new branch of the JDK 10 sandbox
forest (http-client-branch),
and here is the first of a number of changes we want to make.
This one is to address the feedback we received where
HttpResponse.BodyProcessors would
be easier to implement if there was control over the size of buffers
being supplied.
To that end we have added APIs for creating buffered response processors
(and handlers)
So, HttpResponse.BodyProcessor has a new static method with the
following signature
public static <T> BodyProcessor<T> buffering(BodyProcessor<T>
downstream, long buffersize) {}
This returns a new processor which delivers data to the supplied
downstream processor, buffered
by the 'buffersize' parameter. It guarantees that all data is delivered
in chunks of that size
until the final chunk, which may be smaller.
This should allow other BodyProcessor implementations that require
buffering to wrap themselves
in this way, be guaranteed that the data they receive is buffered, and
then return that composite
processor to their user.
A similar method is added to HttpResponse.BodyHandler.
Note also, that we have changed HttpResponse.BodyProcessor from being a
Flow.Subscriber<ByteBuffer>
to Flow.Subscriber(List<ByteBuffer>). That change is technically
orthogonal to this one, but is motivated
by it. By transferring ByteBuffers in lists makes it easier to buffer
them efficiently.
The webrev is at: http://cr.openjdk.java.net/~michaelm/8184285/webrev.1/
Thanks,
Michael
More information about the net-dev
mailing list