author | dfuchs |
Tue, 13 Feb 2018 14:42:41 +0000 | |
branch | http-client-branch |
changeset 56120 | 5db317238575 |
parent 56119 | 33436f5e3b9d |
child 56167 | 96fa4f49a9ff |
permissions | -rw-r--r-- |
56119
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
1 |
/* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
4 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
8 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
14 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
18 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
22 |
*/ |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
23 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
24 |
import java.io.IOException; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
25 |
import java.io.PrintStream; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
26 |
import java.net.http.HttpClient; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
27 |
import java.net.http.HttpRequest; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
28 |
import java.net.http.HttpResponse; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
29 |
import java.net.http.HttpResponse.BodyHandler; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
30 |
import java.util.Collections; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
31 |
import java.util.List; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
32 |
import java.util.concurrent.CopyOnWriteArrayList; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
33 |
import java.util.concurrent.Flow; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
34 |
import java.util.regex.Pattern; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
35 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
36 |
/* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
37 |
* THE CONTENTS OF THIS FILE HAVE TO BE IN SYNC WITH THE EXAMPLES USED IN THE |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
38 |
* JAVADOC. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
39 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
40 |
* @test |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
41 |
* @compile JavadocExamples.java |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
42 |
*/ |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
43 |
public class JavadocExamples { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
44 |
HttpRequest request = null; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
45 |
HttpClient client = null; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
46 |
Pattern p = null; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
47 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
48 |
/** |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
49 |
* @apiNote This method can be used as an adapter between a {@code |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
50 |
* BodySubscriber} and a text based {@code Flow.Subscriber} that parses |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
51 |
* text line by line. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
52 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
53 |
* <p> For example: |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
54 |
* <pre> {@code // A PrintSubscriber that implements Flow.Subscriber<String> |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
55 |
* // and print lines received by onNext() on System.out |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
56 |
* PrintSubscriber subscriber = new PrintSubscriber(System.out); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
57 |
* client.sendAsync(request, BodyHandler.fromLineSubscriber(subscriber)) |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
58 |
* .thenApply(HttpResponse::statusCode) |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
59 |
* .thenAccept((status) -> { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
60 |
* if (status != 200) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
61 |
* System.err.printf("ERROR: %d status received%n", status); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
62 |
* } |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
63 |
* }); }</pre> |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
64 |
*/ |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
65 |
void fromLineSubscriber1() { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
66 |
// A PrintSubscriber that implements Flow.Subscriber<String> |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
67 |
// and print lines received by onNext() on System.out |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
68 |
PrintSubscriber subscriber = new PrintSubscriber(System.out); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
69 |
client.sendAsync(request, BodyHandler.fromLineSubscriber(subscriber)) |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
70 |
.thenApply(HttpResponse::statusCode) |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
71 |
.thenAccept((status) -> { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
72 |
if (status != 200) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
73 |
System.err.printf("ERROR: %d status received%n", status); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
74 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
75 |
}); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
76 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
77 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
78 |
/** |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
79 |
* @apiNote This method can be used as an adapter between a {@code |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
80 |
* BodySubscriber} and a text based {@code Flow.Subscriber} that parses |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
81 |
* text line by line. |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
82 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
83 |
* <p> For example: |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
84 |
* <pre> {@code // A LineParserSubscriber that implements Flow.Subscriber<String> |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
85 |
* // and accumulates lines that match a particular pattern |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
86 |
* Pattern pattern = ...; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
87 |
* LineParserSubscriber subscriber = new LineParserSubscriber(pattern); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
88 |
* HttpResponse<List<String>> response = client.send(request, |
56120
5db317238575
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber (tahe II)
dfuchs
parents:
56119
diff
changeset
|
89 |
* BodyHandler.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n")); |
56119
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
90 |
* if (response.statusCode() != 200) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
91 |
* System.err.printf("ERROR: %d status received%n", response.statusCode()); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
92 |
* } }</pre> |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
93 |
* |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
94 |
*/ |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
95 |
void fromLineSubscriber2() throws IOException, InterruptedException { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
96 |
// A LineParserSubscriber that implements Flow.Subscriber<String> |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
97 |
// and accumulates lines that match a particular pattern |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
98 |
Pattern pattern = p; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
99 |
LineParserSubscriber subscriber = new LineParserSubscriber(pattern); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
100 |
HttpResponse<List<String>> response = client.send(request, |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
101 |
BodyHandler.fromLineSubscriber(subscriber, s -> s.getMatchingLines(), "\n")); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
102 |
if (response.statusCode() != 200) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
103 |
System.err.printf("ERROR: %d status received%n", response.statusCode()); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
104 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
105 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
106 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
107 |
static final class PrintSubscriber implements Flow.Subscriber<String> { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
108 |
final PrintStream out; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
109 |
PrintSubscriber(PrintStream out) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
110 |
this.out = out; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
111 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
112 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
113 |
public void onSubscribe(Flow.Subscription subscription) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
114 |
subscription.request(Long.MAX_VALUE); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
115 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
116 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
117 |
public void onNext(String item) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
118 |
out.println(item); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
119 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
120 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
121 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
122 |
public void onError(Throwable throwable) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
123 |
throwable.printStackTrace(); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
124 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
125 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
126 |
public void onComplete() { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
127 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
128 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
129 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
130 |
static final class LineParserSubscriber implements Flow.Subscriber<String> { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
131 |
final Pattern pattern; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
132 |
final CopyOnWriteArrayList<String> matches = new CopyOnWriteArrayList<>(); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
133 |
LineParserSubscriber(Pattern pattern) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
134 |
this.pattern = pattern; |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
135 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
136 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
137 |
public void onSubscribe(Flow.Subscription subscription) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
138 |
subscription.request(Long.MAX_VALUE); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
139 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
140 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
141 |
public void onNext(String item) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
142 |
if (pattern.matcher(item).matches()) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
143 |
matches.add(item); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
144 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
145 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
146 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
147 |
public void onError(Throwable throwable) { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
148 |
throwable.printStackTrace(); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
149 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
150 |
@Override |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
151 |
public void onComplete() { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
152 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
153 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
154 |
public List<String> getMatchingLines() { |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
155 |
return Collections.unmodifiableList(matches); |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
156 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
157 |
} |
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
158 |
|
33436f5e3b9d
http-client-branch: fix doc examples for BodyHandler::fromLineSubscriber
dfuchs
parents:
diff
changeset
|
159 |
} |