@@ -41,36 +41,47 @@ public class StringPart extends PartBase {
41
41
* Contents of this StringPart.
42
42
*/
43
43
private final byte [] content ;
44
+ private final String value ;
44
45
45
46
private static Charset charsetOrDefault (Charset charset ) {
46
47
return charset == null ? DEFAULT_CHARSET : charset ;
47
48
}
49
+
50
+ private static String contentTypeOrDefault (String contentType ) {
51
+ return contentType == null ? DEFAULT_CONTENT_TYPE : contentType ;
52
+ }
53
+
54
+ private static String transferEncodingOrDefault (String transferEncoding ) {
55
+ return transferEncoding == null ? DEFAULT_TRANSFER_ENCODING : transferEncoding ;
56
+ }
57
+
58
+ public StringPart (String name , String value ) {
59
+ this (name , value , null );
60
+ }
48
61
49
- public StringPart (String name , String value , Charset charset ) {
50
- this (name , value , charset , null );
62
+ public StringPart (String name , String value , String contentType ) {
63
+ this (name , value , contentType , null );
51
64
}
52
65
53
- /**
54
- * Constructor.
55
- *
56
- * @param name
57
- * The name of the part
58
- * @param value
59
- * the string to post
60
- * @param charset
61
- * the charset to be used to encode the string, if <code>null</code> the {@link #DEFAULT_CHARSET default} is used
62
- * @param contentId
63
- * the content id
64
- */
65
- public StringPart (String name , String value , Charset charset , String contentId ) {
66
+ public StringPart (String name , String value , String contentType , Charset charset ) {
67
+ this (name , value , contentType , charset , null );
68
+ }
66
69
67
- super (name , DEFAULT_CONTENT_TYPE , charsetOrDefault (charset ), DEFAULT_TRANSFER_ENCODING , contentId );
70
+ public StringPart (String name , String value , String contentType , Charset charset , String contentId ) {
71
+ this (name , value , contentType , charset , contentId , null );
72
+ }
73
+
74
+ public StringPart (String name , String value , String contentType , Charset charset , String contentId , String transferEncoding ) {
75
+ super (name , contentTypeOrDefault (contentType ), charsetOrDefault (charset ), contentId , transferEncodingOrDefault (transferEncoding ));
68
76
if (value == null )
69
77
throw new NullPointerException ("value" );
78
+
70
79
if (value .indexOf (0 ) != -1 )
71
80
// See RFC 2048, 2.8. "8bit Data"
72
81
throw new IllegalArgumentException ("NULs may not be present in string parts" );
73
- content = value .getBytes (charsetOrDefault (charset ));
82
+
83
+ content = value .getBytes (getCharset ());
84
+ this .value = value ;
74
85
}
75
86
76
87
/**
@@ -104,4 +115,8 @@ public byte[] getBytes(byte[] boundary) throws IOException {
104
115
public long write (WritableByteChannel target , byte [] boundary ) throws IOException {
105
116
return MultipartUtils .writeBytesToChannel (target , getBytes (boundary ));
106
117
}
118
+
119
+ public String getValue () {
120
+ return value ;
121
+ }
107
122
}
0 commit comments