author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 49765 | ee6f7a61f3a5 |
child 56451 | 9585061fdb04 |
permissions | -rw-r--r-- |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
1 |
/* |
49765 | 2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
4 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
8 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
14 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
18 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
21 |
* questions. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
22 |
*/ |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
23 |
|
49765 | 24 |
import java.net.http.HttpClient; |
25 |
import java.net.http.HttpRequest; |
|
26 |
import java.net.http.HttpResponse; |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
27 |
import java.nio.ByteBuffer; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
28 |
import java.nio.MappedByteBuffer; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
29 |
import java.util.Collection; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
30 |
import java.util.List; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
31 |
import java.util.concurrent.Flow; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
32 |
import java.util.function.Function; |
49765 | 33 |
import java.net.http.HttpRequest.BodyPublishers; |
34 |
import java.net.http.HttpResponse.BodyHandler; |
|
35 |
import java.net.http.HttpResponse.BodyHandlers; |
|
36 |
import java.net.http.HttpResponse.BodySubscriber; |
|
37 |
import java.net.http.HttpResponse.BodySubscribers; |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
38 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
39 |
/* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
40 |
* @test |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
41 |
* @summary Basic test for Flow adapters with generic type parameters |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
42 |
* @compile FlowAdaptersCompileOnly.java |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
43 |
*/ |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
44 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
45 |
public class FlowAdaptersCompileOnly { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
46 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
47 |
static void makesSureDifferentGenericSignaturesCompile() { |
49765 | 48 |
BodyPublishers.fromPublisher(new BBPublisher()); |
49 |
BodyPublishers.fromPublisher(new MBBPublisher()); |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
50 |
|
49765 | 51 |
BodyHandlers.fromSubscriber(new ListSubscriber()); |
52 |
BodyHandlers.fromSubscriber(new CollectionSubscriber()); |
|
53 |
BodyHandlers.fromSubscriber(new IterableSubscriber()); |
|
54 |
BodyHandlers.fromSubscriber(new ObjectSubscriber()); |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
55 |
|
49765 | 56 |
BodySubscribers.fromSubscriber(new ListSubscriber()); |
57 |
BodySubscribers.fromSubscriber(new CollectionSubscriber()); |
|
58 |
BodySubscribers.fromSubscriber(new IterableSubscriber()); |
|
59 |
BodySubscribers.fromSubscriber(new ObjectSubscriber()); |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
60 |
|
49765 | 61 |
BodyPublishers.fromPublisher(new BBPublisher(), 1); |
62 |
BodyPublishers.fromPublisher(new MBBPublisher(), 1); |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
63 |
|
49765 | 64 |
BodyHandlers.fromSubscriber(new ListSubscriber(), Function.identity()); |
65 |
BodyHandlers.fromSubscriber(new CollectionSubscriber(), Function.identity()); |
|
66 |
BodyHandlers.fromSubscriber(new IterableSubscriber(), Function.identity()); |
|
67 |
BodyHandlers.fromSubscriber(new ObjectSubscriber(), Function.identity()); |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
68 |
|
49765 | 69 |
BodySubscribers.fromSubscriber(new ListSubscriber(), Function.identity()); |
70 |
BodySubscribers.fromSubscriber(new CollectionSubscriber(), Function.identity()); |
|
71 |
BodySubscribers.fromSubscriber(new IterableSubscriber(), Function.identity()); |
|
72 |
BodySubscribers.fromSubscriber(new ObjectSubscriber(), Function.identity()); |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
73 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
74 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
75 |
static class BBPublisher implements Flow.Publisher<ByteBuffer> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
76 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
77 |
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
78 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
79 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
80 |
static class MBBPublisher implements Flow.Publisher<MappedByteBuffer> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
81 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
82 |
public void subscribe(Flow.Subscriber<? super MappedByteBuffer> subscriber) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
83 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
84 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
85 |
static class ListSubscriber implements Flow.Subscriber<List<ByteBuffer>> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
86 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
87 |
@Override public void onNext(List<ByteBuffer> item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
88 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
89 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
90 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
91 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
92 |
static class CollectionSubscriber implements Flow.Subscriber<Collection<ByteBuffer>> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
93 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
94 |
@Override public void onNext(Collection<ByteBuffer> item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
95 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
96 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
97 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
98 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
99 |
static class IterableSubscriber implements Flow.Subscriber<Iterable<ByteBuffer>> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
100 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
101 |
@Override public void onNext(Iterable<ByteBuffer> item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
102 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
103 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
104 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
105 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
106 |
static class ObjectSubscriber implements Flow.Subscriber<Object> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
107 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
108 |
@Override public void onNext(Object item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
109 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
110 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
111 |
} |
49765 | 112 |
|
113 |
// --- |
|
114 |
||
115 |
static final Function<ListSubscriber,Integer> f1 = subscriber -> 1; |
|
116 |
static final Function<ListSubscriber,Number> f2 = subscriber -> 2; |
|
117 |
static final Function<ListSubscriberX,Integer> f3 = subscriber -> 3; |
|
118 |
static final Function<ListSubscriberX,Number> f4 = subscriber -> 4; |
|
119 |
||
120 |
static class ListSubscriberX extends ListSubscriber { |
|
121 |
int getIntegerX() { return 5; } |
|
122 |
} |
|
123 |
||
124 |
static void makesSureDifferentGenericFunctionSignaturesCompile() { |
|
125 |
BodyHandler<Integer> bh01 = BodyHandlers.fromSubscriber(new ListSubscriber(), s -> 6); |
|
126 |
BodyHandler<Number> bh02 = BodyHandlers.fromSubscriber(new ListSubscriber(), s -> 7); |
|
127 |
BodyHandler<Integer> bh03 = BodyHandlers.fromSubscriber(new ListSubscriber(), f1); |
|
128 |
BodyHandler<Number> bh04 = BodyHandlers.fromSubscriber(new ListSubscriber(), f1); |
|
129 |
BodyHandler<Number> bh05 = BodyHandlers.fromSubscriber(new ListSubscriber(), f2); |
|
130 |
BodyHandler<Integer> bh06 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f1); |
|
131 |
BodyHandler<Number> bh07 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f1); |
|
132 |
BodyHandler<Number> bh08 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f2); |
|
133 |
BodyHandler<Integer> bh09 = BodyHandlers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
|
134 |
BodyHandler<Number> bh10 = BodyHandlers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
|
135 |
BodyHandler<Integer> bh11 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f3); |
|
136 |
BodyHandler<Number> bh12 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f3); |
|
137 |
BodyHandler<Number> bh13 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f4); |
|
138 |
||
139 |
BodySubscriber<Integer> bs01 = BodySubscribers.fromSubscriber(new ListSubscriber(), s -> 6); |
|
140 |
BodySubscriber<Number> bs02 = BodySubscribers.fromSubscriber(new ListSubscriber(), s -> 7); |
|
141 |
BodySubscriber<Integer> bs03 = BodySubscribers.fromSubscriber(new ListSubscriber(), f1); |
|
142 |
BodySubscriber<Number> bs04 = BodySubscribers.fromSubscriber(new ListSubscriber(), f1); |
|
143 |
BodySubscriber<Number> bs05 = BodySubscribers.fromSubscriber(new ListSubscriber(), f2); |
|
144 |
BodySubscriber<Integer> bs06 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f1); |
|
145 |
BodySubscriber<Number> bs07 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f1); |
|
146 |
BodySubscriber<Number> bs08 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f2); |
|
147 |
BodySubscriber<Integer> bs09 = BodySubscribers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
|
148 |
BodySubscriber<Number> bs10 = BodySubscribers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
|
149 |
BodySubscriber<Integer> bs11 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f3); |
|
150 |
BodySubscriber<Number> bs12 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f3); |
|
151 |
BodySubscriber<Number> bs13 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f4); |
|
152 |
} |
|
153 |
||
154 |
// --- |
|
155 |
||
156 |
static class NumberSubscriber implements Flow.Subscriber<List<ByteBuffer>> { |
|
157 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
|
158 |
@Override public void onNext(List<ByteBuffer> item) { } |
|
159 |
@Override public void onError(Throwable throwable) { } |
|
160 |
@Override public void onComplete() { } |
|
161 |
public Number getNumber() { return null; } |
|
162 |
} |
|
163 |
||
164 |
static class IntegerSubscriber extends NumberSubscriber { |
|
165 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
|
166 |
@Override public void onNext(List<ByteBuffer> item) { } |
|
167 |
@Override public void onError(Throwable throwable) { } |
|
168 |
@Override public void onComplete() { } |
|
169 |
public Integer getInteger() { return null; } |
|
170 |
} |
|
171 |
||
172 |
static class LongSubscriber extends NumberSubscriber { |
|
173 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
|
174 |
@Override public void onNext(List<ByteBuffer> item) { } |
|
175 |
@Override public void onError(Throwable throwable) { } |
|
176 |
@Override public void onComplete() { } |
|
177 |
public Long getLong() { return null; } |
|
178 |
} |
|
179 |
||
180 |
static final Function<NumberSubscriber,Number> numMapper = sub -> sub.getNumber(); |
|
181 |
static final Function<IntegerSubscriber,Integer> intMapper = sub -> sub.getInteger(); |
|
182 |
static final Function<LongSubscriber,Long> longMapper = sub -> sub.getLong(); |
|
183 |
||
184 |
public void makesSureDifferentGenericSubscriberSignaturesCompile() |
|
185 |
throws Exception |
|
186 |
{ |
|
187 |
HttpClient client = null; |
|
188 |
HttpRequest request = null; |
|
189 |
IntegerSubscriber sub1 = new IntegerSubscriber(); |
|
190 |
||
191 |
HttpResponse<Integer> r1 = client.send(request, BodyHandlers.fromSubscriber(sub1, IntegerSubscriber::getInteger)); |
|
192 |
HttpResponse<Number> r2 = client.send(request, BodyHandlers.fromSubscriber(sub1, IntegerSubscriber::getInteger)); |
|
193 |
HttpResponse<Number> r3 = client.send(request, BodyHandlers.fromSubscriber(sub1, NumberSubscriber::getNumber)); |
|
194 |
HttpResponse<Integer> r4 = client.send(request, BodyHandlers.fromSubscriber(sub1, intMapper)); |
|
195 |
HttpResponse<Number> r5 = client.send(request, BodyHandlers.fromSubscriber(sub1, intMapper)); |
|
196 |
HttpResponse<Number> r6 = client.send(request, BodyHandlers.fromSubscriber(sub1, numMapper)); |
|
197 |
||
198 |
// compiles but makes little sense. Just what you get with any usage of `? super` |
|
199 |
final Function<Object,Number> objectMapper = sub -> 1; |
|
200 |
client.sendAsync(request, BodyHandlers.fromSubscriber(sub1, objectMapper)); |
|
201 |
||
202 |
// does not compile, as expected ( uncomment to see ) |
|
203 |
//HttpResponse<Number> r7 = client.send(request, BodyHandler.fromSubscriber(sub1, longMapper)); |
|
204 |
} |
|
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
205 |
} |