18
18
import java .nio .channels .WritableByteChannel ;
19
19
import java .nio .charset .Charset ;
20
20
21
+ import org .asynchttpclient .util .StandardCharsets ;
22
+
21
23
public class StringPart extends PartBase {
22
24
23
25
/**
@@ -28,7 +30,7 @@ public class StringPart extends PartBase {
28
30
/**
29
31
* Default charset of string parameters
30
32
*/
31
- public static final String DEFAULT_CHARSET = "US-ASCII" ;
33
+ public static final Charset DEFAULT_CHARSET = StandardCharsets . US_ASCII ;
32
34
33
35
/**
34
36
* Default transfer encoding of string parameters
@@ -40,6 +42,10 @@ public class StringPart extends PartBase {
40
42
*/
41
43
private final byte [] content ;
42
44
45
+ private static Charset charsetOrDefault (String charset ) {
46
+ return charset == null ? DEFAULT_CHARSET : Charset .forName (charset );
47
+ }
48
+
43
49
public StringPart (String name , String value , String charset ) {
44
50
this (name , value , charset , null );
45
51
}
@@ -58,15 +64,13 @@ public StringPart(String name, String value, String charset) {
58
64
*/
59
65
public StringPart (String name , String value , String charset , String contentId ) {
60
66
61
- super (name , DEFAULT_CONTENT_TYPE , charset == null ? DEFAULT_CHARSET : charset , DEFAULT_TRANSFER_ENCODING , contentId );
62
- if (value == null ) {
67
+ super (name , DEFAULT_CONTENT_TYPE , charsetOrDefault ( charset ). name () , DEFAULT_TRANSFER_ENCODING , contentId );
68
+ if (value == null )
63
69
throw new NullPointerException ("value" );
64
- }
65
- if (value .indexOf (0 ) != -1 ) {
70
+ if (value .indexOf (0 ) != -1 )
66
71
// See RFC 2048, 2.8. "8bit Data"
67
72
throw new IllegalArgumentException ("NULs may not be present in string parts" );
68
- }
69
- content = value .getBytes (Charset .forName (charset ));
73
+ content = value .getBytes (charsetOrDefault (charset ));
70
74
}
71
75
72
76
/**
0 commit comments