@@ -75,6 +75,36 @@ void asLines_async() throws ExecutionException, InterruptedException {
7575 assertThat (lines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
7676 }
7777
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+
78108 @ Test
79109 void asInputStream () throws IOException {
80110 final HttpResponse <InputStream > hres =
@@ -84,13 +114,7 @@ void asInputStream() throws IOException {
84114 .asInputStream ();
85115
86116 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 );
94118 assertThat (allLines ).hasSize (4 );
95119 assertThat (allLines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
96120 }
@@ -104,15 +128,49 @@ void asInputStream_async() throws IOException, ExecutionException, InterruptedEx
104128
105129 final HttpResponse <InputStream > hres = future .get ();
106130 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+ }
108165
166+ private List <String > readLines (HttpResponse <InputStream > hres ) throws IOException {
167+ final LineNumberReader reader = new LineNumberReader (new InputStreamReader (hres .body ()));
109168 List <String > allLines = new ArrayList <>();
110169 String line ;
111170 while ((line = reader .readLine ()) != null ) {
112171 allLines .add (line );
113172 }
114- assertThat (allLines ).hasSize (4 );
115- assertThat (allLines .get (0 )).contains ("{\" id\" :1, \" name\" :\" one\" }" );
173+ return allLines ;
116174 }
117175
118176 @ Test
@@ -353,6 +411,26 @@ void callStringAsync() throws ExecutionException, InterruptedException {
353411 assertThat (hres .statusCode ()).isEqualTo (200 );
354412 }
355413
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+
356434 @ Test
357435 void callWithHandler () {
358436 final HttpResponse <String > hres = clientContext .request ()
0 commit comments