@@ -75,6 +75,36 @@ void asLines_async() throws ExecutionException, InterruptedException {
75
75
assertThat (lines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
76
76
}
77
77
78
+ @ Test
79
+ void asLines_callExecute () {
80
+ final HttpResponse <Stream <String >> hres =
81
+ clientContext .request ()
82
+ .path ("hello" ).path ("stream" )
83
+ .GET ()
84
+ .call ().asLines ().execute ();
85
+
86
+ assertThat (hres .statusCode ()).isEqualTo (200 );
87
+ final List <String > lines = hres .body ().collect (Collectors .toList ());
88
+
89
+ assertThat (lines ).hasSize (4 );
90
+ assertThat (lines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
91
+ }
92
+
93
+ @ Test
94
+ void asLines_callAsync () throws ExecutionException , InterruptedException {
95
+ final HttpResponse <Stream <String >> hres =
96
+ clientContext .request ()
97
+ .path ("hello" ).path ("stream" )
98
+ .GET ()
99
+ .call ().asLines ().async ().get ();
100
+
101
+ assertThat (hres .statusCode ()).isEqualTo (200 );
102
+ final List <String > lines = hres .body ().collect (Collectors .toList ());
103
+
104
+ assertThat (lines ).hasSize (4 );
105
+ assertThat (lines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
106
+ }
107
+
78
108
@ Test
79
109
void asInputStream () throws IOException {
80
110
final HttpResponse <InputStream > hres =
@@ -84,13 +114,7 @@ void asInputStream() throws IOException {
84
114
.asInputStream ();
85
115
86
116
assertThat (hres .statusCode ()).isEqualTo (200 );
87
- final LineNumberReader reader = new LineNumberReader (new InputStreamReader (hres .body ()));
88
-
89
- List <String > allLines = new ArrayList <>();
90
- String line ;
91
- while ((line = reader .readLine ()) != null ) {
92
- allLines .add (line );
93
- }
117
+ List <String > allLines = readLines (hres );
94
118
assertThat (allLines ).hasSize (4 );
95
119
assertThat (allLines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
96
120
}
@@ -104,15 +128,49 @@ void asInputStream_async() throws IOException, ExecutionException, InterruptedEx
104
128
105
129
final HttpResponse <InputStream > hres = future .get ();
106
130
assertThat (hres .statusCode ()).isEqualTo (200 );
107
- final LineNumberReader reader = new LineNumberReader (new InputStreamReader (hres .body ()));
131
+ List <String > allLines = readLines (hres );
132
+ assertThat (allLines ).hasSize (4 );
133
+ assertThat (allLines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
134
+ }
135
+
136
+ @ Test
137
+ void asInputStream_callExecute () throws IOException {
138
+ final HttpResponse <InputStream > hres =
139
+ clientContext .request ()
140
+ .path ("hello" ).path ("stream" )
141
+ .GET ()
142
+ .call ()
143
+ .asInputStream ().execute ();
144
+
145
+ assertThat (hres .statusCode ()).isEqualTo (200 );
146
+ List <String > allLines = readLines (hres );
147
+ assertThat (allLines ).hasSize (4 );
148
+ assertThat (allLines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
149
+ }
150
+
151
+ @ Test
152
+ void asInputStream_callAsync () throws IOException , ExecutionException , InterruptedException {
153
+ final HttpResponse <InputStream > hres =
154
+ clientContext .request ()
155
+ .path ("hello" ).path ("stream" )
156
+ .GET ()
157
+ .call ()
158
+ .asInputStream ().async ().get ();
159
+
160
+ assertThat (hres .statusCode ()).isEqualTo (200 );
161
+ List <String > allLines = readLines (hres );
162
+ assertThat (allLines ).hasSize (4 );
163
+ assertThat (allLines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
164
+ }
108
165
166
+ private List <String > readLines (HttpResponse <InputStream > hres ) throws IOException {
167
+ final LineNumberReader reader = new LineNumberReader (new InputStreamReader (hres .body ()));
109
168
List <String > allLines = new ArrayList <>();
110
169
String line ;
111
170
while ((line = reader .readLine ()) != null ) {
112
171
allLines .add (line );
113
172
}
114
- assertThat (allLines ).hasSize (4 );
115
- assertThat (allLines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
173
+ return allLines ;
116
174
}
117
175
118
176
@ Test
@@ -353,6 +411,26 @@ void callStringAsync() throws ExecutionException, InterruptedException {
353
411
assertThat (hres .statusCode ()).isEqualTo (200 );
354
412
}
355
413
414
+ @ Test
415
+ void callBytes () {
416
+ final HttpResponse <byte []> hres = clientContext .request ()
417
+ .path ("hello" ).path ("message" )
418
+ .GET ().call ().asByteArray ().execute ();
419
+
420
+ assertThat (new String (hres .body (), StandardCharsets .UTF_8 )).contains ("hello world" );
421
+ assertThat (hres .statusCode ()).isEqualTo (200 );
422
+ }
423
+
424
+ @ Test
425
+ void callBytesAsync () throws ExecutionException , InterruptedException {
426
+ final HttpResponse <byte []> hres = clientContext .request ()
427
+ .path ("hello" ).path ("message" )
428
+ .GET ().call ().asByteArray ().async ().get ();
429
+
430
+ assertThat (new String (hres .body (), StandardCharsets .UTF_8 )).contains ("hello world" );
431
+ assertThat (hres .statusCode ()).isEqualTo (200 );
432
+ }
433
+
356
434
@ Test
357
435
void callWithHandler () {
358
436
final HttpResponse <String > hres = clientContext .request ()
0 commit comments