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