author | michaelm |
Fri, 16 Feb 2018 10:34:17 +0000 | |
branch | http-client-branch |
changeset 56137 | dd867826d55b |
parent 56097 | 15dc43936d39 |
child 56138 | 4f92b988600e |
permissions | -rw-r--r-- |
48083 | 1 |
/* |
56009
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
48083 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
26 |
package jdk.internal.net.http; |
48083 | 27 |
|
56009
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
28 |
import java.io.BufferedReader; |
48083 | 29 |
import java.io.IOException; |
30 |
import java.io.InputStream; |
|
56009
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
31 |
import java.io.InputStreamReader; |
48083 | 32 |
import java.lang.System.Logger.Level; |
33 |
import java.nio.ByteBuffer; |
|
34 |
import java.nio.channels.FileChannel; |
|
56009
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
35 |
import java.nio.charset.Charset; |
48083 | 36 |
import java.nio.file.OpenOption; |
37 |
import java.nio.file.Path; |
|
38 |
import java.security.AccessControlContext; |
|
39 |
import java.security.AccessController; |
|
40 |
import java.security.PrivilegedActionException; |
|
41 |
import java.security.PrivilegedExceptionAction; |
|
42 |
import java.util.ArrayList; |
|
43 |
import java.util.Iterator; |
|
44 |
import java.util.List; |
|
45 |
import java.util.Objects; |
|
46 |
import java.util.Optional; |
|
47 |
import java.util.concurrent.ArrayBlockingQueue; |
|
48 |
import java.util.concurrent.BlockingQueue; |
|
49 |
import java.util.concurrent.CompletableFuture; |
|
50 |
import java.util.concurrent.CompletionStage; |
|
51 |
import java.util.concurrent.Flow; |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
52 |
import java.util.concurrent.Flow.Subscriber; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
53 |
import java.util.concurrent.Flow.Subscription; |
48083 | 54 |
import java.util.concurrent.atomic.AtomicBoolean; |
55 |
import java.util.function.Consumer; |
|
56 |
import java.util.function.Function; |
|
56009
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
57 |
import java.util.stream.Stream; |
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56082
diff
changeset
|
58 |
import java.net.http.HttpResponse.BodySubscriber; |
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
59 |
import jdk.internal.net.http.common.MinimalFuture; |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
60 |
import jdk.internal.net.http.common.Utils; |
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
61 |
import static java.nio.charset.StandardCharsets.UTF_8; |
48083 | 62 |
|
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
63 |
public class ResponseSubscribers { |
48083 | 64 |
|
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
65 |
public static class ConsumerSubscriber implements BodySubscriber<Void> { |
48083 | 66 |
private final Consumer<Optional<byte[]>> consumer; |
67 |
private Flow.Subscription subscription; |
|
68 |
private final CompletableFuture<Void> result = new MinimalFuture<>(); |
|
69 |
private final AtomicBoolean subscribed = new AtomicBoolean(); |
|
70 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
71 |
public ConsumerSubscriber(Consumer<Optional<byte[]>> consumer) { |
48379
5382baab8371
8193698: Null handling in BodyPublisher, BodyHandler, and BodySubscriber convenience static factory methods
chegar
parents:
48083
diff
changeset
|
72 |
this.consumer = Objects.requireNonNull(consumer); |
48083 | 73 |
} |
74 |
||
75 |
@Override |
|
76 |
public CompletionStage<Void> getBody() { |
|
77 |
return result; |
|
78 |
} |
|
79 |
||
80 |
@Override |
|
81 |
public void onSubscribe(Flow.Subscription subscription) { |
|
82 |
if (!subscribed.compareAndSet(false, true)) { |
|
83 |
subscription.cancel(); |
|
84 |
} else { |
|
85 |
this.subscription = subscription; |
|
86 |
subscription.request(1); |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
@Override |
|
91 |
public void onNext(List<ByteBuffer> items) { |
|
92 |
for (ByteBuffer item : items) { |
|
93 |
byte[] buf = new byte[item.remaining()]; |
|
94 |
item.get(buf); |
|
95 |
consumer.accept(Optional.of(buf)); |
|
96 |
} |
|
97 |
subscription.request(1); |
|
98 |
} |
|
99 |
||
100 |
@Override |
|
101 |
public void onError(Throwable throwable) { |
|
102 |
result.completeExceptionally(throwable); |
|
103 |
} |
|
104 |
||
105 |
@Override |
|
106 |
public void onComplete() { |
|
107 |
consumer.accept(Optional.empty()); |
|
108 |
result.complete(null); |
|
109 |
} |
|
110 |
||
111 |
} |
|
112 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
113 |
public static class PathSubscriber implements BodySubscriber<Path> { |
48083 | 114 |
|
115 |
private final Path file; |
|
116 |
private final CompletableFuture<Path> result = new MinimalFuture<>(); |
|
117 |
||
118 |
private volatile Flow.Subscription subscription; |
|
119 |
private volatile FileChannel out; |
|
120 |
private volatile AccessControlContext acc; |
|
121 |
private final OpenOption[] options; |
|
122 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
123 |
public PathSubscriber(Path file, OpenOption... options) { |
48083 | 124 |
this.file = file; |
125 |
this.options = options; |
|
126 |
} |
|
127 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
128 |
public void setAccessControlContext(AccessControlContext acc) { |
48083 | 129 |
this.acc = acc; |
130 |
} |
|
131 |
||
132 |
@Override |
|
133 |
public void onSubscribe(Flow.Subscription subscription) { |
|
134 |
if (System.getSecurityManager() != null && acc == null) |
|
135 |
throw new InternalError( |
|
136 |
"Unexpected null acc when security manager has been installed"); |
|
137 |
||
138 |
this.subscription = subscription; |
|
139 |
try { |
|
140 |
PrivilegedExceptionAction<FileChannel> pa = |
|
141 |
() -> FileChannel.open(file, options); |
|
142 |
out = AccessController.doPrivileged(pa, acc); |
|
143 |
} catch (PrivilegedActionException pae) { |
|
144 |
Throwable t = pae.getCause() != null ? pae.getCause() : pae; |
|
145 |
result.completeExceptionally(t); |
|
146 |
subscription.cancel(); |
|
147 |
return; |
|
148 |
} |
|
149 |
subscription.request(1); |
|
150 |
} |
|
151 |
||
152 |
@Override |
|
153 |
public void onNext(List<ByteBuffer> items) { |
|
154 |
try { |
|
155 |
out.write(items.toArray(Utils.EMPTY_BB_ARRAY)); |
|
156 |
} catch (IOException ex) { |
|
157 |
Utils.close(out); |
|
158 |
subscription.cancel(); |
|
159 |
result.completeExceptionally(ex); |
|
160 |
} |
|
161 |
subscription.request(1); |
|
162 |
} |
|
163 |
||
164 |
@Override |
|
165 |
public void onError(Throwable e) { |
|
166 |
result.completeExceptionally(e); |
|
167 |
Utils.close(out); |
|
168 |
} |
|
169 |
||
170 |
@Override |
|
171 |
public void onComplete() { |
|
172 |
Utils.close(out); |
|
173 |
result.complete(file); |
|
174 |
} |
|
175 |
||
176 |
@Override |
|
177 |
public CompletionStage<Path> getBody() { |
|
178 |
return result; |
|
179 |
} |
|
180 |
} |
|
181 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
182 |
public static class ByteArraySubscriber<T> implements BodySubscriber<T> { |
48083 | 183 |
private final Function<byte[], T> finisher; |
184 |
private final CompletableFuture<T> result = new MinimalFuture<>(); |
|
185 |
private final List<ByteBuffer> received = new ArrayList<>(); |
|
186 |
||
187 |
private volatile Flow.Subscription subscription; |
|
188 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
189 |
public ByteArraySubscriber(Function<byte[],T> finisher) { |
48083 | 190 |
this.finisher = finisher; |
191 |
} |
|
192 |
||
193 |
@Override |
|
194 |
public void onSubscribe(Flow.Subscription subscription) { |
|
195 |
if (this.subscription != null) { |
|
196 |
subscription.cancel(); |
|
197 |
return; |
|
198 |
} |
|
199 |
this.subscription = subscription; |
|
200 |
// We can handle whatever you've got |
|
201 |
subscription.request(Long.MAX_VALUE); |
|
202 |
} |
|
203 |
||
204 |
@Override |
|
205 |
public void onNext(List<ByteBuffer> items) { |
|
206 |
// incoming buffers are allocated by http client internally, |
|
207 |
// and won't be used anywhere except this place. |
|
208 |
// So it's free simply to store them for further processing. |
|
209 |
assert Utils.hasRemaining(items); |
|
56071 | 210 |
received.addAll(items); |
48083 | 211 |
} |
212 |
||
213 |
@Override |
|
214 |
public void onError(Throwable throwable) { |
|
215 |
received.clear(); |
|
216 |
result.completeExceptionally(throwable); |
|
217 |
} |
|
218 |
||
219 |
static private byte[] join(List<ByteBuffer> bytes) { |
|
220 |
int size = Utils.remaining(bytes, Integer.MAX_VALUE); |
|
221 |
byte[] res = new byte[size]; |
|
222 |
int from = 0; |
|
223 |
for (ByteBuffer b : bytes) { |
|
224 |
int l = b.remaining(); |
|
225 |
b.get(res, from, l); |
|
226 |
from += l; |
|
227 |
} |
|
228 |
return res; |
|
229 |
} |
|
230 |
||
231 |
@Override |
|
232 |
public void onComplete() { |
|
233 |
try { |
|
234 |
result.complete(finisher.apply(join(received))); |
|
235 |
received.clear(); |
|
236 |
} catch (IllegalArgumentException e) { |
|
237 |
result.completeExceptionally(e); |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
@Override |
|
242 |
public CompletionStage<T> getBody() { |
|
243 |
return result; |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
/** |
|
248 |
* An InputStream built on top of the Flow API. |
|
249 |
*/ |
|
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
250 |
public static class HttpResponseInputStream extends InputStream |
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
251 |
implements BodySubscriber<InputStream> |
48083 | 252 |
{ |
253 |
final static boolean DEBUG = Utils.DEBUG; |
|
254 |
final static int MAX_BUFFERS_IN_QUEUE = 1; // lock-step with the producer |
|
255 |
||
256 |
// An immutable ByteBuffer sentinel to mark that the last byte was received. |
|
257 |
private static final ByteBuffer LAST_BUFFER = ByteBuffer.wrap(new byte[0]); |
|
258 |
private static final List<ByteBuffer> LAST_LIST = List.of(LAST_BUFFER); |
|
259 |
private static final System.Logger DEBUG_LOGGER = |
|
260 |
Utils.getDebugLogger("HttpResponseInputStream"::toString, DEBUG); |
|
261 |
||
262 |
// A queue of yet unprocessed ByteBuffers received from the flow API. |
|
263 |
private final BlockingQueue<List<ByteBuffer>> buffers; |
|
264 |
private volatile Flow.Subscription subscription; |
|
265 |
private volatile boolean closed; |
|
266 |
private volatile Throwable failed; |
|
267 |
private volatile Iterator<ByteBuffer> currentListItr; |
|
268 |
private volatile ByteBuffer currentBuffer; |
|
269 |
private final AtomicBoolean subscribed = new AtomicBoolean(); |
|
270 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
271 |
public HttpResponseInputStream() { |
48083 | 272 |
this(MAX_BUFFERS_IN_QUEUE); |
273 |
} |
|
274 |
||
275 |
HttpResponseInputStream(int maxBuffers) { |
|
276 |
int capacity = (maxBuffers <= 0 ? MAX_BUFFERS_IN_QUEUE : maxBuffers); |
|
277 |
// 1 additional slot needed for LAST_LIST added by onComplete |
|
278 |
this.buffers = new ArrayBlockingQueue<>(capacity + 1); |
|
279 |
} |
|
280 |
||
281 |
@Override |
|
282 |
public CompletionStage<InputStream> getBody() { |
|
283 |
// Returns the stream immediately, before the |
|
284 |
// response body is received. |
|
56035 | 285 |
// This makes it possible for sendAsync().get().body() |
48083 | 286 |
// to complete before the response body is received. |
287 |
return CompletableFuture.completedStage(this); |
|
288 |
} |
|
289 |
||
290 |
// Returns the current byte buffer to read from. |
|
291 |
// If the current buffer has no remaining data, this method will take the |
|
292 |
// next buffer from the buffers queue, possibly blocking until |
|
293 |
// a new buffer is made available through the Flow API, or the |
|
294 |
// end of the flow has been reached. |
|
295 |
private ByteBuffer current() throws IOException { |
|
296 |
while (currentBuffer == null || !currentBuffer.hasRemaining()) { |
|
297 |
// Check whether the stream is closed or exhausted |
|
298 |
if (closed || failed != null) { |
|
299 |
throw new IOException("closed", failed); |
|
300 |
} |
|
301 |
if (currentBuffer == LAST_BUFFER) break; |
|
302 |
||
303 |
try { |
|
304 |
if (currentListItr == null || !currentListItr.hasNext()) { |
|
305 |
// Take a new list of buffers from the queue, blocking |
|
306 |
// if none is available yet... |
|
307 |
||
308 |
DEBUG_LOGGER.log(Level.DEBUG, "Taking list of Buffers"); |
|
309 |
List<ByteBuffer> lb = buffers.take(); |
|
310 |
currentListItr = lb.iterator(); |
|
311 |
DEBUG_LOGGER.log(Level.DEBUG, "List of Buffers Taken"); |
|
312 |
||
313 |
// Check whether an exception was encountered upstream |
|
314 |
if (closed || failed != null) |
|
315 |
throw new IOException("closed", failed); |
|
316 |
||
317 |
// Check whether we're done. |
|
318 |
if (lb == LAST_LIST) { |
|
319 |
currentListItr = null; |
|
320 |
currentBuffer = LAST_BUFFER; |
|
321 |
break; |
|
322 |
} |
|
323 |
||
324 |
// Request another upstream item ( list of buffers ) |
|
325 |
Flow.Subscription s = subscription; |
|
326 |
if (s != null) { |
|
327 |
DEBUG_LOGGER.log(Level.DEBUG, "Increased demand by 1"); |
|
328 |
s.request(1); |
|
329 |
} |
|
330 |
assert currentListItr != null; |
|
331 |
if (lb.isEmpty()) continue; |
|
332 |
} |
|
333 |
assert currentListItr != null; |
|
334 |
assert currentListItr.hasNext(); |
|
335 |
DEBUG_LOGGER.log(Level.DEBUG, "Next Buffer"); |
|
336 |
currentBuffer = currentListItr.next(); |
|
337 |
} catch (InterruptedException ex) { |
|
338 |
// continue |
|
339 |
} |
|
340 |
} |
|
341 |
assert currentBuffer == LAST_BUFFER || currentBuffer.hasRemaining(); |
|
342 |
return currentBuffer; |
|
343 |
} |
|
344 |
||
345 |
@Override |
|
346 |
public int read(byte[] bytes, int off, int len) throws IOException { |
|
347 |
// get the buffer to read from, possibly blocking if |
|
348 |
// none is available |
|
349 |
ByteBuffer buffer; |
|
350 |
if ((buffer = current()) == LAST_BUFFER) return -1; |
|
351 |
||
352 |
// don't attempt to read more than what is available |
|
353 |
// in the current buffer. |
|
354 |
int read = Math.min(buffer.remaining(), len); |
|
355 |
assert read > 0 && read <= buffer.remaining(); |
|
356 |
||
357 |
// buffer.get() will do the boundary check for us. |
|
358 |
buffer.get(bytes, off, read); |
|
359 |
return read; |
|
360 |
} |
|
361 |
||
362 |
@Override |
|
363 |
public int read() throws IOException { |
|
364 |
ByteBuffer buffer; |
|
365 |
if ((buffer = current()) == LAST_BUFFER) return -1; |
|
366 |
return buffer.get() & 0xFF; |
|
367 |
} |
|
368 |
||
369 |
@Override |
|
370 |
public void onSubscribe(Flow.Subscription s) { |
|
371 |
try { |
|
372 |
if (!subscribed.compareAndSet(false, true)) { |
|
373 |
s.cancel(); |
|
374 |
} else { |
|
375 |
// check whether the stream is already closed. |
|
376 |
// if so, we should cancel the subscription |
|
377 |
// immediately. |
|
378 |
boolean closed; |
|
379 |
synchronized (this) { |
|
380 |
closed = this.closed; |
|
381 |
if (!closed) { |
|
382 |
this.subscription = s; |
|
383 |
} |
|
384 |
} |
|
385 |
if (closed) { |
|
386 |
s.cancel(); |
|
387 |
return; |
|
388 |
} |
|
389 |
assert buffers.remainingCapacity() > 1; // should contain at least 2 |
|
390 |
DEBUG_LOGGER.log(Level.DEBUG, () -> "onSubscribe: requesting " |
|
391 |
+ Math.max(1, buffers.remainingCapacity() - 1)); |
|
392 |
s.request(Math.max(1, buffers.remainingCapacity() - 1)); |
|
393 |
} |
|
394 |
} catch (Throwable t) { |
|
395 |
failed = t; |
|
396 |
try { |
|
397 |
close(); |
|
398 |
} catch (IOException x) { |
|
399 |
// OK |
|
400 |
} finally { |
|
401 |
onError(t); |
|
402 |
} |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
@Override |
|
407 |
public void onNext(List<ByteBuffer> t) { |
|
408 |
Objects.requireNonNull(t); |
|
409 |
try { |
|
410 |
DEBUG_LOGGER.log(Level.DEBUG, "next item received"); |
|
411 |
if (!buffers.offer(t)) { |
|
412 |
throw new IllegalStateException("queue is full"); |
|
413 |
} |
|
414 |
DEBUG_LOGGER.log(Level.DEBUG, "item offered"); |
|
415 |
} catch (Throwable ex) { |
|
416 |
failed = ex; |
|
417 |
try { |
|
418 |
close(); |
|
419 |
} catch (IOException ex1) { |
|
420 |
// OK |
|
421 |
} finally { |
|
422 |
onError(ex); |
|
423 |
} |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
@Override |
|
428 |
public void onError(Throwable thrwbl) { |
|
429 |
subscription = null; |
|
430 |
failed = Objects.requireNonNull(thrwbl); |
|
431 |
// The client process that reads the input stream might |
|
432 |
// be blocked in queue.take(). |
|
433 |
// Tries to offer LAST_LIST to the queue. If the queue is |
|
434 |
// full we don't care if we can't insert this buffer, as |
|
435 |
// the client can't be blocked in queue.take() in that case. |
|
436 |
// Adding LAST_LIST to the queue is harmless, as the client |
|
437 |
// should find failed != null before handling LAST_LIST. |
|
438 |
buffers.offer(LAST_LIST); |
|
439 |
} |
|
440 |
||
441 |
@Override |
|
442 |
public void onComplete() { |
|
443 |
subscription = null; |
|
444 |
onNext(LAST_LIST); |
|
445 |
} |
|
446 |
||
447 |
@Override |
|
448 |
public void close() throws IOException { |
|
449 |
Flow.Subscription s; |
|
450 |
synchronized (this) { |
|
451 |
if (closed) return; |
|
452 |
closed = true; |
|
453 |
s = subscription; |
|
454 |
subscription = null; |
|
455 |
} |
|
456 |
// s will be null if already completed |
|
457 |
try { |
|
458 |
if (s != null) { |
|
459 |
s.cancel(); |
|
460 |
} |
|
461 |
} finally { |
|
462 |
buffers.offer(LAST_LIST); |
|
463 |
super.close(); |
|
464 |
} |
|
465 |
} |
|
466 |
||
467 |
} |
|
468 |
||
56082
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
469 |
public static BodySubscriber<Stream<String>> createLineStream() { |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
470 |
return createLineStream(UTF_8); |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
471 |
} |
56009
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
472 |
|
56082
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
473 |
public static BodySubscriber<Stream<String>> createLineStream(Charset charset) { |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
474 |
Objects.requireNonNull(charset); |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
475 |
BodySubscriber<InputStream> s = new HttpResponseInputStream(); |
56097
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
476 |
return new MappingSubscriber<InputStream,Stream<String>>(s, |
56082
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
477 |
(InputStream stream) -> { |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
478 |
return new BufferedReader(new InputStreamReader(stream, charset)) |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
479 |
.lines().onClose(() -> Utils.close(stream)); |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
480 |
}); |
56009
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
481 |
} |
cf8792f51dee
http-client-branch: Adds some convenience methods to parse body responses as lines
dfuchs
parents:
56008
diff
changeset
|
482 |
|
48083 | 483 |
/** |
484 |
* Currently this consumes all of the data and ignores it |
|
485 |
*/ |
|
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
486 |
public static class NullSubscriber<T> implements BodySubscriber<T> { |
48083 | 487 |
|
488 |
private final CompletableFuture<T> cf = new MinimalFuture<>(); |
|
489 |
private final Optional<T> result; |
|
490 |
private final AtomicBoolean subscribed = new AtomicBoolean(); |
|
491 |
||
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
492 |
public NullSubscriber(Optional<T> result) { |
48083 | 493 |
this.result = result; |
494 |
} |
|
495 |
||
496 |
@Override |
|
497 |
public void onSubscribe(Flow.Subscription subscription) { |
|
498 |
if (!subscribed.compareAndSet(false, true)) { |
|
499 |
subscription.cancel(); |
|
500 |
} else { |
|
501 |
subscription.request(Long.MAX_VALUE); |
|
502 |
} |
|
503 |
} |
|
504 |
||
505 |
@Override |
|
506 |
public void onNext(List<ByteBuffer> items) { |
|
507 |
Objects.requireNonNull(items); |
|
508 |
} |
|
509 |
||
510 |
@Override |
|
511 |
public void onError(Throwable throwable) { |
|
512 |
cf.completeExceptionally(throwable); |
|
513 |
} |
|
514 |
||
515 |
@Override |
|
516 |
public void onComplete() { |
|
517 |
if (result.isPresent()) { |
|
518 |
cf.complete(result.get()); |
|
519 |
} else { |
|
520 |
cf.complete(null); |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
@Override |
|
525 |
public CompletionStage<T> getBody() { |
|
526 |
return cf; |
|
527 |
} |
|
528 |
} |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
529 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
530 |
/** An adapter between {@code BodySubscriber} and {@code Flow.Subscriber}. */ |
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
531 |
public static final class SubscriberAdapter<S extends Subscriber<? super List<ByteBuffer>>,R> |
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
532 |
implements BodySubscriber<R> |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
533 |
{ |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
534 |
private final CompletableFuture<R> cf = new MinimalFuture<>(); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
535 |
private final S subscriber; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
536 |
private final Function<S,R> finisher; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
537 |
private volatile Subscription subscription; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
538 |
|
56077
3f6b75adcdc0
http-client-branch: move ResponseSubscribers to internal
chegar
parents:
56071
diff
changeset
|
539 |
public SubscriberAdapter(S subscriber, Function<S,R> finisher) { |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
540 |
this.subscriber = Objects.requireNonNull(subscriber); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
541 |
this.finisher = Objects.requireNonNull(finisher); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
542 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
543 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
544 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
545 |
public void onSubscribe(Subscription subscription) { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
546 |
Objects.requireNonNull(subscription); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
547 |
if (this.subscription != null) { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
548 |
subscription.cancel(); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
549 |
} else { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
550 |
this.subscription = subscription; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
551 |
subscriber.onSubscribe(subscription); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
552 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
553 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
554 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
555 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
556 |
public void onNext(List<ByteBuffer> item) { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
557 |
Objects.requireNonNull(item); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
558 |
try { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
559 |
subscriber.onNext(item); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
560 |
} catch (Throwable throwable) { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
561 |
subscription.cancel(); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
562 |
onError(throwable); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
563 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
564 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
565 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
566 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
567 |
public void onError(Throwable throwable) { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
568 |
Objects.requireNonNull(throwable); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
569 |
try { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
570 |
subscriber.onError(throwable); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
571 |
} finally { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
572 |
cf.completeExceptionally(throwable); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
573 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
574 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
575 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
576 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
577 |
public void onComplete() { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
578 |
try { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
579 |
subscriber.onComplete(); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
580 |
} finally { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
581 |
try { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
582 |
cf.complete(finisher.apply(subscriber)); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
583 |
} catch (Throwable throwable) { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
584 |
cf.completeExceptionally(throwable); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
585 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
586 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
587 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
588 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
589 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
590 |
public CompletionStage<R> getBody() { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
591 |
return cf; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
592 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
48379
diff
changeset
|
593 |
} |
56082
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
594 |
|
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
595 |
/** |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
596 |
* A body subscriber which receives input from an upstream subscriber |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
597 |
* and maps that subscriber's body type to a new type. The upstream subscriber |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
598 |
* delegates all flow operations directly to this object. The |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
599 |
* {@link CompletionStage} returned by {@link #getBody()}} takes the output |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
600 |
* of the upstream {@code getBody()} and applies the mapper function to |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
601 |
* obtain the new {@code CompletionStage} type. |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
602 |
* |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
603 |
* @param <T> the upstream body type |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
604 |
* @param <U> this subscriber's body type |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
605 |
*/ |
56097
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
606 |
public static class MappingSubscriber<T,U> implements BodySubscriber<U> { |
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
607 |
private final BodySubscriber<T> upstream; |
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
608 |
private final Function<T,U> mapper; |
56082
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
609 |
|
56097
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
610 |
public MappingSubscriber(BodySubscriber<T> upstream, Function<T,U> mapper) { |
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
611 |
this.upstream = Objects.requireNonNull(upstream); |
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
612 |
this.mapper = Objects.requireNonNull(mapper); |
56082
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
613 |
} |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
614 |
|
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
615 |
@Override |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
616 |
public CompletionStage<U> getBody() { |
56097
15dc43936d39
http-client-branch: javadoc refresh and minor fixes
chegar
parents:
56092
diff
changeset
|
617 |
return upstream.getBody().thenApply(mapper); |
56082
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
618 |
} |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
619 |
|
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
620 |
@Override |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
621 |
public void onSubscribe(Flow.Subscription subscription) { |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
622 |
upstream.onSubscribe(subscription); |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
623 |
} |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
624 |
|
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
625 |
@Override |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
626 |
public void onNext(List<ByteBuffer> item) { |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
627 |
upstream.onNext(item); |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
628 |
} |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
629 |
|
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
630 |
@Override |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
631 |
public void onError(Throwable throwable) { |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
632 |
upstream.onError(throwable); |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
633 |
} |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
634 |
|
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
635 |
@Override |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
636 |
public void onComplete() { |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
637 |
upstream.onComplete(); |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
638 |
} |
1da51fab3032
http-client-branch: added mapping subscriber, miscellaneous bug fixes and change to discard()/replace() subscribers
michaelm
parents:
56077
diff
changeset
|
639 |
} |
48083 | 640 |
} |