@@ -77,22 +77,32 @@ public void writeLastBoundaryIfNeeds() {
77
77
return ;
78
78
}
79
79
80
- writeBoundary ();
80
+ try {
81
+ out .write (("--" + boundary + "--\r \n " ).getBytes ());
82
+ out .flush ();
83
+ } catch (final IOException e ) {
84
+ e .printStackTrace ();
85
+ }
81
86
82
87
isSetLast = true ;
83
88
}
84
89
85
- public void addPart (final String key , final String value ) {
90
+ public void addPart (final String key , final String value , final String contentType ) {
86
91
writeBoundary ();
87
92
try {
88
- out .write (("Content-Disposition: form-data; name=\" " +key +"\" \r \n \r \n " ).getBytes ());
93
+ out .write (("Content-Disposition: form-data; name=\" " +key +"\" \r \n " ).getBytes ());
94
+ out .write (("Content-Type: " + contentType + "\r \n \r \n " ).getBytes ());
89
95
out .write (value .getBytes ());
90
96
out .write (("\r \n " ).getBytes ());
91
97
} catch (final IOException e ) {
92
98
e .printStackTrace ();
93
99
}
94
100
}
95
101
102
+ public void addPart (final String key , final String value ) {
103
+ addPart (key ,value ,"text/plain; charset=UTF-8" );
104
+ }
105
+
96
106
public void addPart (final String key , final String fileName , final InputStream fin , final boolean isLast ){
97
107
addPart (key , fileName , fin , "application/octet-stream" , isLast );
98
108
}
@@ -111,7 +121,7 @@ public void addPart(final String key, final String fileName, final InputStream f
111
121
out .write (tmp , 0 , l );
112
122
}
113
123
out .write (("\r \n " ).getBytes ());
114
- out . flush ();
124
+
115
125
} catch (final IOException e ) {
116
126
e .printStackTrace ();
117
127
} finally {
@@ -159,6 +169,7 @@ public boolean isStreaming() {
159
169
160
170
@ Override
161
171
public void writeTo (final OutputStream outstream ) throws IOException {
172
+ writeLastBoundaryIfNeeds ();
162
173
outstream .write (out .toByteArray ());
163
174
}
164
175
@@ -179,6 +190,7 @@ public void consumeContent() throws IOException,
179
190
@ Override
180
191
public InputStream getContent () throws IOException ,
181
192
UnsupportedOperationException {
193
+ writeLastBoundaryIfNeeds ();
182
194
return new ByteArrayInputStream (out .toByteArray ());
183
195
}
184
196
}
0 commit comments