23
23
24
24
/**
25
25
* This class is an adaptation of the Apache HttpClient implementation
26
- *
26
+ *
27
27
* @link http://hc.apache.org/httpclient-3.x/
28
28
*/
29
29
public class FilePart extends PartBase {
@@ -51,43 +51,40 @@ public class FilePart extends PartBase {
51
51
/**
52
52
* Attachment's file name as a byte array
53
53
*/
54
- private static final byte [] FILE_NAME_BYTES =
55
- MultipartEncodingUtil .getAsciiBytes (FILE_NAME );
54
+ private static final byte [] FILE_NAME_BYTES = MultipartEncodingUtil .getAsciiBytes (FILE_NAME );
56
55
57
56
/**
58
57
* Source of the file part.
59
58
*/
60
- private PartSource source ;
59
+ private final PartSource source ;
61
60
62
61
/**
63
62
* FilePart Constructor.
64
- *
65
- * @param name the name for this part
66
- * @param partSource the source for this part
67
- * @param contentType the content type for this part, if <code>null</code> the
68
- * {@link #DEFAULT_CONTENT_TYPE default} is used
69
- * @param charset the charset encoding for this part, if <code>null</code> the
70
- * {@link #DEFAULT_CHARSET default} is used
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
68
+ * @param contentId
71
69
*/
72
- public FilePart (String name , PartSource partSource , String contentType , String charset ) {
70
+ public FilePart (String name , PartSource partSource , String contentType , String charset , String contentId ) {
73
71
74
- super (
75
- name ,
76
- contentType == null ? DEFAULT_CONTENT_TYPE : contentType ,
77
- charset == null ? "ISO-8859-1" : charset ,
78
- DEFAULT_TRANSFER_ENCODING
79
- );
72
+ super (name , contentType == null ? DEFAULT_CONTENT_TYPE : contentType , charset == null ? "ISO-8859-1" : charset , DEFAULT_TRANSFER_ENCODING , contentId );
80
73
81
74
if (partSource == null ) {
82
75
throw new IllegalArgumentException ("Source may not be null" );
83
76
}
84
77
this .source = partSource ;
85
78
}
79
+
80
+ public FilePart (String name , PartSource partSource , String contentType , String charset ) {
81
+ this (name , partSource , contentType , charset , null );
82
+ }
86
83
87
84
/**
88
85
* FilePart Constructor.
89
- *
90
- * @param name the name for this part
86
+ *
87
+ * @param name the name for this part
91
88
* @param partSource the source for this part
92
89
*/
93
90
public FilePart (String name , PartSource partSource ) {
@@ -96,77 +93,64 @@ public FilePart(String name, PartSource partSource) {
96
93
97
94
/**
98
95
* FilePart Constructor.
99
- *
96
+ *
100
97
* @param name the name of the file part
101
98
* @param file the file to post
102
- * @throws java.io.FileNotFoundException if the <i>file</i> is not a normal
103
- * file or if it is not readable.
99
+ * @throws java.io.FileNotFoundException if the <i>file</i> is not a normal file or if it is not readable.
104
100
*/
105
- public FilePart (String name , File file )
106
- throws FileNotFoundException {
101
+ public FilePart (String name , File file ) throws FileNotFoundException {
107
102
this (name , new FilePartSource (file ), null , null );
108
103
}
109
104
110
105
/**
111
106
* FilePart Constructor.
112
- *
113
- * @param name the name of the file part
114
- * @param file the file to post
115
- * @param contentType the content type for this part, if <code>null</code> the
116
- * {@link #DEFAULT_CONTENT_TYPE default} is used
117
- * @param charset the charset encoding for this part, if <code>null</code> the
118
- * {@link #DEFAULT_CHARSET default} is used
119
- * @throws FileNotFoundException if the <i>file</i> is not a normal
120
- * file or if it is not readable.
121
- */
122
- public FilePart (String name , File file , String contentType , String charset )
123
- throws FileNotFoundException {
107
+ *
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.
113
+ */
114
+ public FilePart (String name , File file , String contentType , String charset ) throws FileNotFoundException {
124
115
this (name , new FilePartSource (file ), contentType , charset );
125
116
}
126
117
127
118
/**
128
119
* FilePart Constructor.
129
- *
130
- * @param name the name of the file part
120
+ *
121
+ * @param name the name of the file part
131
122
* @param fileName the file name
132
- * @param file the file to post
133
- * @throws FileNotFoundException if the <i>file</i> is not a normal
134
- * file or if it is not readable.
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
125
*/
136
- public FilePart (String name , String fileName , File file )
137
- throws FileNotFoundException {
126
+ public FilePart (String name , String fileName , File file ) throws FileNotFoundException {
138
127
this (name , new FilePartSource (fileName , file ), null , null );
139
128
}
140
129
141
130
/**
142
131
* FilePart Constructor.
143
- *
144
- * @param name the name of the file part
145
- * @param fileName the file name
146
- * @param file the file to post
147
- * @param contentType the content type for this part, if <code>null</code> the
148
- * {@link #DEFAULT_CONTENT_TYPE default} is used
149
- * @param charset the charset encoding for this part, if <code>null</code> the
150
- * {@link #DEFAULT_CHARSET default} is used
151
- * @throws FileNotFoundException if the <i>file</i> is not a normal
152
- * file or if it is not readable.
153
- */
154
- public FilePart (String name , String fileName , File file , String contentType , String charset )
155
- throws FileNotFoundException {
132
+ *
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.
139
+ */
140
+ public FilePart (String name , String fileName , File file , String contentType , String charset ) throws FileNotFoundException {
156
141
this (name , new FilePartSource (fileName , file ), contentType , charset );
157
142
}
158
143
159
144
/**
160
145
* Write the disposition header to the output stream
161
- *
146
+ *
162
147
* @param out The output stream
163
148
* @throws java.io.IOException If an IO problem occurs
164
149
*/
165
- protected void sendDispositionHeader (OutputStream out )
166
- throws IOException {
167
- super .sendDispositionHeader (out );
150
+ protected void sendDispositionHeader (OutputStream out ) throws IOException {
168
151
String filename = this .source .getFileName ();
169
152
if (filename != null ) {
153
+ super .sendDispositionHeader (out );
170
154
out .write (FILE_NAME_BYTES );
171
155
out .write (QUOTE_BYTES );
172
156
out .write (MultipartEncodingUtil .getAsciiBytes (filename ));
@@ -176,7 +160,7 @@ protected void sendDispositionHeader(OutputStream out)
176
160
177
161
/**
178
162
* Write the data in "source" to the specified stream.
179
- *
163
+ *
180
164
* @param out The output stream.
181
165
* @throws IOException if an IO problem occurs.
182
166
*/
@@ -202,17 +186,17 @@ protected void sendData(OutputStream out) throws IOException {
202
186
}
203
187
}
204
188
205
- public void setStalledTime (long ms ) {
206
- _stalledTime = ms ;
207
- }
189
+ public void setStalledTime (long ms ) {
190
+ _stalledTime = ms ;
191
+ }
208
192
209
- public long getStalledTime () {
210
- return _stalledTime ;
211
- }
193
+ public long getStalledTime () {
194
+ return _stalledTime ;
195
+ }
212
196
213
197
/**
214
198
* Returns the source of the file part.
215
- *
199
+ *
216
200
* @return The source.
217
201
*/
218
202
protected PartSource getSource () {
@@ -221,14 +205,14 @@ protected PartSource getSource() {
221
205
222
206
/**
223
207
* Return the length of the data.
224
- *
208
+ *
225
209
* @return The length.
226
210
* @throws IOException if an IO problem occurs
227
211
*/
228
212
protected long lengthOfData () throws IOException {
229
213
return source .getLength ();
230
214
}
231
215
232
- private long _stalledTime = -1 ;
216
+ private long _stalledTime = -1 ;
233
217
234
218
}
0 commit comments