12
12
*/
13
13
package com .ning .http .client .multipart ;
14
14
15
+ import com .ning .http .util .StandardCharsets ;
16
+
15
17
import java .io .ByteArrayOutputStream ;
16
18
import java .io .IOException ;
17
19
import java .io .OutputStream ;
@@ -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
@@ -45,6 +47,10 @@ public StringPart(String name, String value, String charset) {
45
47
this (name , value , charset , null );
46
48
}
47
49
50
+ private static Charset charsetOrDefault (String charset ) {
51
+ return charset == null ? DEFAULT_CHARSET : Charset .forName (charset );
52
+ }
53
+
48
54
/**
49
55
* Constructor.
50
56
*
@@ -58,15 +64,15 @@ public StringPart(String name, String value, String charset) {
58
64
* the content id
59
65
*/
60
66
public StringPart (String name , String value , String charset , String contentId ) {
61
- super (name , DEFAULT_CONTENT_TYPE , charset == null ? DEFAULT_CHARSET : charset , contentId , DEFAULT_TRANSFER_ENCODING );
62
- if (value == null ) {
67
+ super (name , DEFAULT_CONTENT_TYPE , charsetOrDefault ( charset ). name () , contentId , DEFAULT_TRANSFER_ENCODING );
68
+ if (value == null )
63
69
throw new NullPointerException ("value" );
64
- }
65
- if (value .indexOf (0 ) != -1 ) {
70
+
71
+ if (value .indexOf (0 ) != -1 )
66
72
// See RFC 2048, 2.8. "8bit Data"
67
73
throw new IllegalArgumentException ("NULs may not be present in string parts" );
68
- }
69
- content = value .getBytes (Charset . forName (charset ));
74
+
75
+ content = value .getBytes (charsetOrDefault (charset ));
70
76
this .value = value ;
71
77
}
72
78
0 commit comments