< prev index next >
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ResponseContent.java
Print this page
@@ -25,10 +25,11 @@
package jdk.incubator.http;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import jdk.incubator.http.internal.common.Utils;
/**
@@ -43,22 +44,22 @@
final HttpConnection connection;
final int contentLength;
ByteBuffer buffer;
//ByteBuffer lastBufferUsed;
final ResponseHeaders headers;
- private final Consumer<Optional<ByteBuffer>> dataConsumer;
+ private final Consumer<Optional<List<ByteBuffer>>> dataConsumer;
private final Consumer<IOException> errorConsumer;
private final HttpClientImpl client;
// this needs to run before we complete the body
// so that connection can be returned to pool
private final Runnable onFinished;
ResponseContent(HttpConnection connection,
int contentLength,
ResponseHeaders h,
HttpResponse.BodyProcessor<?> userProcessor,
- Consumer<Optional<ByteBuffer>> dataConsumer,
+ Consumer<Optional<List<ByteBuffer>>> dataConsumer,
Consumer<IOException> errorConsumer,
Runnable onFinished)
{
this.pusher = (HttpResponse.BodyProcessor)userProcessor;
this.connection = connection;
@@ -225,11 +226,11 @@
chunkbuf = b;
while (true) {
ByteBuffer b1 = readChunkedBuffer();
if (b1 != null) {
if (b1.hasRemaining()) {
- dataConsumer.accept(Optional.of(b1));
+ dataConsumer.accept(Optional.of(List.of(b1)));
}
} else {
onFinished.run();
dataConsumer.accept(Optional.empty());
return;
@@ -256,11 +257,11 @@
ByteBuffer buffer = Utils.getBuffer();
int amount = Math.min(b.remaining(), remaining);
Utils.copy(b, buffer, amount);
remaining -= amount;
buffer.flip();
- dataConsumer.accept(Optional.of(buffer));
+ dataConsumer.accept(Optional.of(List.of(buffer)));
}
while (remaining > 0) {
ByteBuffer buffer = connection.read();
if (buffer == null)
throw new IOException("connection closed");
@@ -269,11 +270,11 @@
// assume for now that pipelining not implemented
if (bytesread > remaining) {
throw new IOException("too many bytes read");
}
remaining -= bytesread;
- dataConsumer.accept(Optional.of(buffer));
+ dataConsumer.accept(Optional.of(List.of(buffer)));
}
onFinished.run();
dataConsumer.accept(Optional.empty());
}
}
< prev index next >