@@ -61,10 +61,14 @@ public class FilePart extends PartBase {
61
61
/**
62
62
* FilePart Constructor.
63
63
*
64
- * @param name the name for this part
65
- * @param partSource the source for this part
66
- * @param contentType the content type for this part, if <code>null</code> the {@link #DEFAULT_CONTENT_TYPE default} is used
67
- * @param charset the charset encoding for this part, if <code>null</code> the {@link #DEFAULT_CHARSET default} is used
64
+ * @param name
65
+ * the name for this part
66
+ * @param partSource
67
+ * the source for this part
68
+ * @param contentType
69
+ * the content type for this part, if <code>null</code> the {@link #DEFAULT_CONTENT_TYPE default} is used
70
+ * @param charset
71
+ * the charset encoding for this part, if <code>null</code> the {@link #DEFAULT_CHARSET default} is used
68
72
* @param contentId
69
73
*/
70
74
public FilePart (String name , PartSource partSource , String contentType , String charset , String contentId ) {
@@ -76,16 +80,18 @@ public FilePart(String name, PartSource partSource, String contentType, String c
76
80
}
77
81
this .source = partSource ;
78
82
}
79
-
83
+
80
84
public FilePart (String name , PartSource partSource , String contentType , String charset ) {
81
85
this (name , partSource , contentType , charset , null );
82
86
}
83
87
84
88
/**
85
89
* FilePart Constructor.
86
90
*
87
- * @param name the name for this part
88
- * @param partSource the source for this part
91
+ * @param name
92
+ * the name for this part
93
+ * @param partSource
94
+ * the source for this part
89
95
*/
90
96
public FilePart (String name , PartSource partSource ) {
91
97
this (name , partSource , null , null );
@@ -94,9 +100,12 @@ public FilePart(String name, PartSource partSource) {
94
100
/**
95
101
* FilePart Constructor.
96
102
*
97
- * @param name the name of the file part
98
- * @param file the file to post
99
- * @throws java.io.FileNotFoundException if the <i>file</i> is not a normal file or if it is not readable.
103
+ * @param name
104
+ * the name of the file part
105
+ * @param file
106
+ * the file to post
107
+ * @throws java.io.FileNotFoundException
108
+ * if the <i>file</i> is not a normal file or if it is not readable.
100
109
*/
101
110
public FilePart (String name , File file ) throws FileNotFoundException {
102
111
this (name , new FilePartSource (file ), null , null );
@@ -105,11 +114,16 @@ public FilePart(String name, File file) throws FileNotFoundException {
105
114
/**
106
115
* FilePart Constructor.
107
116
*
108
- * @param name the name of the file part
109
- * @param file the file to post
110
- * @param contentType the content type for this part, if <code>null</code> the {@link #DEFAULT_CONTENT_TYPE default} is used
111
- * @param charset the charset encoding for this part, if <code>null</code> the {@link #DEFAULT_CHARSET default} is used
112
- * @throws FileNotFoundException if the <i>file</i> is not a normal file or if it is not readable.
117
+ * @param name
118
+ * the name of the file part
119
+ * @param file
120
+ * the file to post
121
+ * @param contentType
122
+ * the content type for this part, if <code>null</code> the {@link #DEFAULT_CONTENT_TYPE default} is used
123
+ * @param charset
124
+ * the charset encoding for this part, if <code>null</code> the {@link #DEFAULT_CHARSET default} is used
125
+ * @throws FileNotFoundException
126
+ * if the <i>file</i> is not a normal file or if it is not readable.
113
127
*/
114
128
public FilePart (String name , File file , String contentType , String charset ) throws FileNotFoundException {
115
129
this (name , new FilePartSource (file ), contentType , charset );
@@ -118,10 +132,14 @@ public FilePart(String name, File file, String contentType, String charset) thro
118
132
/**
119
133
* FilePart Constructor.
120
134
*
121
- * @param name the name of the file part
122
- * @param fileName the file name
123
- * @param file the file to post
124
- * @throws FileNotFoundException if the <i>file</i> is not a normal file or if it is not readable.
135
+ * @param name
136
+ * the name of the file part
137
+ * @param fileName
138
+ * the file name
139
+ * @param file
140
+ * the file to post
141
+ * @throws FileNotFoundException
142
+ * if the <i>file</i> is not a normal file or if it is not readable.
125
143
*/
126
144
public FilePart (String name , String fileName , File file ) throws FileNotFoundException {
127
145
this (name , new FilePartSource (fileName , file ), null , null );
@@ -130,12 +148,18 @@ public FilePart(String name, String fileName, File file) throws FileNotFoundExce
130
148
/**
131
149
* FilePart Constructor.
132
150
*
133
- * @param name the name of the file part
134
- * @param fileName the file name
135
- * @param file the file to post
136
- * @param contentType the content type for this part, if <code>null</code> the {@link #DEFAULT_CONTENT_TYPE default} is used
137
- * @param charset the charset encoding for this part, if <code>null</code> the {@link #DEFAULT_CHARSET default} is used
138
- * @throws FileNotFoundException if the <i>file</i> is not a normal file or if it is not readable.
151
+ * @param name
152
+ * the name of the file part
153
+ * @param fileName
154
+ * the file name
155
+ * @param file
156
+ * the file to post
157
+ * @param contentType
158
+ * the content type for this part, if <code>null</code> the {@link #DEFAULT_CONTENT_TYPE default} is used
159
+ * @param charset
160
+ * the charset encoding for this part, if <code>null</code> the {@link #DEFAULT_CHARSET default} is used
161
+ * @throws FileNotFoundException
162
+ * if the <i>file</i> is not a normal file or if it is not readable.
139
163
*/
140
164
public FilePart (String name , String fileName , File file , String contentType , String charset ) throws FileNotFoundException {
141
165
this (name , new FilePartSource (fileName , file ), contentType , charset );
@@ -144,8 +168,10 @@ public FilePart(String name, String fileName, File file, String contentType, Str
144
168
/**
145
169
* Write the disposition header to the output stream
146
170
*
147
- * @param out The output stream
148
- * @throws java.io.IOException If an IO problem occurs
171
+ * @param out
172
+ * The output stream
173
+ * @throws java.io.IOException
174
+ * If an IO problem occurs
149
175
*/
150
176
protected void sendDispositionHeader (OutputStream out ) throws IOException {
151
177
super .sendDispositionHeader (out );
@@ -158,11 +184,25 @@ protected void sendDispositionHeader(OutputStream out) throws IOException {
158
184
}
159
185
}
160
186
187
+ protected long dispositionHeaderLength () {
188
+ String filename = this .source .getFileName ();
189
+ long length = super .dispositionHeaderLength ();
190
+ if (filename != null ) {
191
+ length += FILE_NAME_BYTES .length ;
192
+ length += QUOTE_BYTES .length ;
193
+ length += MultipartEncodingUtil .getAsciiBytes (filename ).length ;
194
+ length += QUOTE_BYTES .length ;
195
+ }
196
+ return length ;
197
+ }
198
+
161
199
/**
162
200
* Write the data in "source" to the specified stream.
163
201
*
164
- * @param out The output stream.
165
- * @throws IOException if an IO problem occurs.
202
+ * @param out
203
+ * The output stream.
204
+ * @throws IOException
205
+ * if an IO problem occurs.
166
206
*/
167
207
protected void sendData (OutputStream out ) throws IOException {
168
208
if (lengthOfData () == 0 ) {
@@ -207,9 +247,8 @@ protected PartSource getSource() {
207
247
* Return the length of the data.
208
248
*
209
249
* @return The length.
210
- * @throws IOException if an IO problem occurs
211
250
*/
212
- protected long lengthOfData () throws IOException {
251
+ protected long lengthOfData () {
213
252
return source .getLength ();
214
253
}
215
254
0 commit comments