Skip to content

Commit b7a0ae2

Browse files
author
Stephane Landelle
committed
Multiparts should support Content-ID header, close AsyncHttpClient#296
1 parent c14a962 commit b7a0ae2

File tree

5 files changed

+179
-170
lines changed

5 files changed

+179
-170
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@
466466
<exclude>**/NettyResponse</exclude>
467467
<exclude>**/AsyncHttpProviderUtils</exclude>
468468
<exclude>**/Cookie</exclude>
469+
<exclude>**/Part</exclude>
470+
<exclude>**/PartBase</exclude>
469471
</excludes>
470472
</configuration>
471473
<executions>

src/main/java/com/ning/http/multipart/FilePart.java

Lines changed: 53 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* This class is an adaptation of the Apache HttpClient implementation
26-
*
26+
*
2727
* @link http://hc.apache.org/httpclient-3.x/
2828
*/
2929
public class FilePart extends PartBase {
@@ -51,43 +51,39 @@ public class FilePart extends PartBase {
5151
/**
5252
* Attachment's file name as a byte array
5353
*/
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);
5655

5756
/**
5857
* Source of the file part.
5958
*/
60-
private PartSource source;
59+
private final PartSource source;
6160

6261
/**
6362
* 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
7168
*/
72-
public FilePart(String name, PartSource partSource, String contentType, String charset) {
69+
public FilePart(String name, PartSource partSource, String contentType, String charset, String contentId) {
7370

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);
8072

8173
if (partSource == null) {
8274
throw new IllegalArgumentException("Source may not be null");
8375
}
8476
this.source = partSource;
8577
}
8678

79+
public FilePart(String name, PartSource partSource, String contentType, String charset) {
80+
this(name, partSource, contentType, charset, null);
81+
}
82+
8783
/**
8884
* FilePart Constructor.
89-
*
90-
* @param name the name for this part
85+
*
86+
* @param name the name for this part
9187
* @param partSource the source for this part
9288
*/
9389
public FilePart(String name, PartSource partSource) {
@@ -96,74 +92,61 @@ public FilePart(String name, PartSource partSource) {
9692

9793
/**
9894
* FilePart Constructor.
99-
*
95+
*
10096
* @param name the name of the file part
10197
* @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.
10499
*/
105-
public FilePart(String name, File file)
106-
throws FileNotFoundException {
100+
public FilePart(String name, File file) throws FileNotFoundException {
107101
this(name, new FilePartSource(file), null, null);
108102
}
109103

110104
/**
111105
* 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 {
124114
this(name, new FilePartSource(file), contentType, charset);
125115
}
126116

127117
/**
128118
* FilePart Constructor.
129-
*
130-
* @param name the name of the file part
119+
*
120+
* @param name the name of the file part
131121
* @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.
135124
*/
136-
public FilePart(String name, String fileName, File file)
137-
throws FileNotFoundException {
125+
public FilePart(String name, String fileName, File file) throws FileNotFoundException {
138126
this(name, new FilePartSource(fileName, file), null, null);
139127
}
140128

141129
/**
142130
* 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 {
156140
this(name, new FilePartSource(fileName, file), contentType, charset);
157141
}
158142

159143
/**
160144
* Write the disposition header to the output stream
161-
*
145+
*
162146
* @param out The output stream
163147
* @throws java.io.IOException If an IO problem occurs
164148
*/
165-
protected void sendDispositionHeader(OutputStream out)
166-
throws IOException {
149+
protected void sendDispositionHeader(OutputStream out) throws IOException {
167150
super.sendDispositionHeader(out);
168151
String filename = this.source.getFileName();
169152
if (filename != null) {
@@ -176,7 +159,7 @@ protected void sendDispositionHeader(OutputStream out)
176159

177160
/**
178161
* Write the data in "source" to the specified stream.
179-
*
162+
*
180163
* @param out The output stream.
181164
* @throws IOException if an IO problem occurs.
182165
*/
@@ -202,17 +185,17 @@ protected void sendData(OutputStream out) throws IOException {
202185
}
203186
}
204187

205-
public void setStalledTime(long ms) {
206-
_stalledTime = ms;
207-
}
188+
public void setStalledTime(long ms) {
189+
_stalledTime = ms;
190+
}
208191

209-
public long getStalledTime() {
210-
return _stalledTime;
211-
}
192+
public long getStalledTime() {
193+
return _stalledTime;
194+
}
212195

213196
/**
214197
* Returns the source of the file part.
215-
*
198+
*
216199
* @return The source.
217200
*/
218201
protected PartSource getSource() {
@@ -221,14 +204,14 @@ protected PartSource getSource() {
221204

222205
/**
223206
* Return the length of the data.
224-
*
207+
*
225208
* @return The length.
226209
* @throws IOException if an IO problem occurs
227210
*/
228211
protected long lengthOfData() throws IOException {
229212
return source.getLength();
230213
}
231214

232-
private long _stalledTime = -1;
215+
private long _stalledTime = -1;
233216

234217
}

0 commit comments

Comments
 (0)