@@ -77,22 +77,32 @@ public void writeLastBoundaryIfNeeds() {
7777            return ;
7878        }
7979
80-         writeBoundary ();
80+         try  {
81+             out .write (("--"  + boundary  + "--\r \n " ).getBytes ());
82+             out .flush ();
83+         } catch  (final  IOException  e ) {
84+             e .printStackTrace ();
85+         }
8186
8287        isSetLast  = true ;
8388    }
8489
85-     public  void  addPart (final  String  key , final  String  value ) {
90+     public  void  addPart (final  String  key , final  String  value ,  final   String   contentType ) {
8691        writeBoundary ();
8792        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 ());
8995            out .write (value .getBytes ());
9096            out .write (("\r \n " ).getBytes ());
9197        } catch  (final  IOException  e ) {
9298            e .printStackTrace ();
9399        }
94100    }
95101
102+     public  void  addPart (final  String  key , final  String  value ) {
103+         addPart (key ,value ,"text/plain; charset=UTF-8" );
104+     }
105+ 
96106    public  void  addPart (final  String  key , final  String  fileName , final  InputStream  fin , final  boolean  isLast ){
97107        addPart (key , fileName , fin , "application/octet-stream" , isLast );
98108    }
@@ -111,7 +121,7 @@ public void addPart(final String key, final String fileName, final InputStream f
111121                out .write (tmp , 0 , l );
112122            }
113123            out .write (("\r \n " ).getBytes ());
114-             out . flush (); 
124+             
115125        } catch  (final  IOException  e ) {
116126            e .printStackTrace ();
117127        } finally  {
@@ -159,6 +169,7 @@ public boolean isStreaming() {
159169
160170    @ Override 
161171    public  void  writeTo (final  OutputStream  outstream ) throws  IOException  {
172+         writeLastBoundaryIfNeeds ();
162173        outstream .write (out .toByteArray ());
163174    }
164175
@@ -179,6 +190,7 @@ public void consumeContent() throws IOException,
179190    @ Override 
180191    public  InputStream  getContent () throws  IOException ,
181192    UnsupportedOperationException  {
193+     	writeLastBoundaryIfNeeds ();
182194        return  new  ByteArrayInputStream (out .toByteArray ());
183195    }
184196}
0 commit comments