15
15
*/
16
16
package org .asynchttpclient ;
17
17
18
+ import static org .asynchttpclient .util .AsyncHttpProviderUtils .parseCharset ;
19
+ import static org .asynchttpclient .util .AsyncHttpProviderUtils .validateSupportedScheme ;
18
20
import static org .asynchttpclient .util .MiscUtils .isNonEmpty ;
19
- import static org .asynchttpclient .util .AsyncHttpProviderUtils .*;
20
21
21
22
import java .io .File ;
22
23
import java .io .InputStream ;
23
24
import java .net .InetAddress ;
25
+ import java .nio .ByteBuffer ;
24
26
import java .nio .charset .Charset ;
25
27
import java .util .ArrayList ;
26
28
import java .util .Collection ;
@@ -59,6 +61,7 @@ private static final class RequestImpl implements Request {
59
61
private byte [] byteData ;
60
62
private List <byte []> compositeByteData ;
61
63
private String stringData ;
64
+ private ByteBuffer byteBufferData ;
62
65
private InputStream streamData ;
63
66
private BodyGenerator bodyGenerator ;
64
67
private List <Param > formParams ;
@@ -90,6 +93,7 @@ public RequestImpl(Request prototype) {
90
93
this .byteData = prototype .getByteData ();
91
94
this .compositeByteData = prototype .getCompositeByteData ();
92
95
this .stringData = prototype .getStringData ();
96
+ this .byteBufferData = prototype .getByteBufferData ();
93
97
this .streamData = prototype .getStreamData ();
94
98
this .bodyGenerator = prototype .getBodyGenerator ();
95
99
this .formParams = prototype .getFormParams () == null ? null : new ArrayList <>(prototype .getFormParams ());
@@ -158,6 +162,11 @@ public String getStringData() {
158
162
return stringData ;
159
163
}
160
164
165
+ @ Override
166
+ public ByteBuffer getByteBufferData () {
167
+ return byteBufferData ;
168
+ }
169
+
161
170
@ Override
162
171
public InputStream getStreamData () {
163
172
return streamData ;
@@ -414,6 +423,7 @@ public void resetFormParams() {
414
423
public void resetNonMultipartData () {
415
424
request .byteData = null ;
416
425
request .compositeByteData = null ;
426
+ request .byteBufferData = null ;
417
427
request .stringData = null ;
418
428
request .streamData = null ;
419
429
request .bodyGenerator = null ;
@@ -429,34 +439,38 @@ public T setBody(File file) {
429
439
return derived .cast (this );
430
440
}
431
441
432
- public T setBody ( byte [] data ) {
442
+ private void resetBody ( ) {
433
443
resetFormParams ();
434
444
resetNonMultipartData ();
435
445
resetMultipartData ();
446
+ }
447
+
448
+ public T setBody (byte [] data ) {
449
+ resetBody ();
436
450
request .byteData = data ;
437
451
return derived .cast (this );
438
452
}
439
453
440
454
public T setBody (List <byte []> data ) {
441
- resetFormParams ();
442
- resetNonMultipartData ();
443
- resetMultipartData ();
455
+ resetBody ();
444
456
request .compositeByteData = data ;
445
457
return derived .cast (this );
446
458
}
447
459
448
460
public T setBody (String data ) {
449
- resetFormParams ();
450
- resetNonMultipartData ();
451
- resetMultipartData ();
461
+ resetBody ();
452
462
request .stringData = data ;
453
463
return derived .cast (this );
454
464
}
455
465
466
+ public T setBody (ByteBuffer data ) {
467
+ resetBody ();
468
+ request .byteBufferData = data ;
469
+ return derived .cast (this );
470
+ }
471
+
456
472
public T setBody (InputStream stream ) {
457
- resetFormParams ();
458
- resetNonMultipartData ();
459
- resetMultipartData ();
473
+ resetBody ();
460
474
request .streamData = stream ;
461
475
return derived .cast (this );
462
476
}
0 commit comments