< prev index next >

src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/ResponseContent.java

Print this page

        

*** 25,34 **** --- 25,35 ---- 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,64 **** final HttpConnection connection; final int contentLength; ByteBuffer buffer; //ByteBuffer lastBufferUsed; final ResponseHeaders headers; ! private final Consumer<Optional<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<IOException> errorConsumer, Runnable onFinished) { this.pusher = (HttpResponse.BodyProcessor)userProcessor; this.connection = connection; --- 44,65 ---- final HttpConnection connection; final int contentLength; ByteBuffer buffer; //ByteBuffer lastBufferUsed; final ResponseHeaders headers; ! 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<List<ByteBuffer>>> dataConsumer, Consumer<IOException> errorConsumer, Runnable onFinished) { this.pusher = (HttpResponse.BodyProcessor)userProcessor; this.connection = connection;
*** 225,235 **** chunkbuf = b; while (true) { ByteBuffer b1 = readChunkedBuffer(); if (b1 != null) { if (b1.hasRemaining()) { ! dataConsumer.accept(Optional.of(b1)); } } else { onFinished.run(); dataConsumer.accept(Optional.empty()); return; --- 226,236 ---- chunkbuf = b; while (true) { ByteBuffer b1 = readChunkedBuffer(); if (b1 != null) { if (b1.hasRemaining()) { ! dataConsumer.accept(Optional.of(List.of(b1))); } } else { onFinished.run(); dataConsumer.accept(Optional.empty()); return;
*** 256,266 **** 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)); } while (remaining > 0) { ByteBuffer buffer = connection.read(); if (buffer == null) throw new IOException("connection closed"); --- 257,267 ---- ByteBuffer buffer = Utils.getBuffer(); int amount = Math.min(b.remaining(), remaining); Utils.copy(b, buffer, amount); remaining -= amount; buffer.flip(); ! dataConsumer.accept(Optional.of(List.of(buffer))); } while (remaining > 0) { ByteBuffer buffer = connection.read(); if (buffer == null) throw new IOException("connection closed");
*** 269,279 **** // assume for now that pipelining not implemented if (bytesread > remaining) { throw new IOException("too many bytes read"); } remaining -= bytesread; ! dataConsumer.accept(Optional.of(buffer)); } onFinished.run(); dataConsumer.accept(Optional.empty()); } } --- 270,280 ---- // assume for now that pipelining not implemented if (bytesread > remaining) { throw new IOException("too many bytes read"); } remaining -= bytesread; ! dataConsumer.accept(Optional.of(List.of(buffer))); } onFinished.run(); dataConsumer.accept(Optional.empty()); } }
< prev index next >