Skip to content

Commit dc8e3a8

Browse files
author
Stephane Landelle
committed
Make transferEncoding configurable, fix FilePart constructors, close AsyncHttpClient#647
1 parent 2655fcf commit dc8e3a8

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

src/main/java/com/ning/http/client/multipart/AbstractFilePart.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ public abstract class AbstractFilePart extends PartBase {
5555
* @param charset
5656
* the charset encoding for this part
5757
*/
58-
public AbstractFilePart(String name, String contentType, String charset, String contentId) {
59-
super(name, contentType == null ? DEFAULT_CONTENT_TYPE : contentType, charset,
60-
DEFAULT_TRANSFER_ENCODING, contentId);
58+
public AbstractFilePart(String name, String contentType, String charset, String contentId, String transferEncoding) {
59+
super(name,//
60+
contentType == null ? DEFAULT_CONTENT_TYPE : contentType,//
61+
charset,//
62+
contentId, //
63+
transferEncoding == null ? DEFAULT_TRANSFER_ENCODING : transferEncoding);
6164
}
6265

6366
protected void visitDispositionHeader(PartVisitor visitor) throws IOException {

src/main/java/com/ning/http/client/multipart/ByteArrayPart.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ public ByteArrayPart(String name, byte[] bytes, String contentType, String chars
3737
}
3838

3939
public ByteArrayPart(String name, byte[] bytes, String contentType, String charset, String fileName, String contentId) {
40-
super(name, contentType, charset, contentId);
41-
if (bytes == null) {
40+
this(name, bytes, contentType, charset, fileName, contentId, null);
41+
}
42+
43+
public ByteArrayPart(String name, byte[] bytes, String contentType, String charset, String fileName, String contentId, String transferEncoding) {
44+
super(name, contentType, charset, contentId, transferEncoding);
45+
if (bytes == null)
4246
throw new NullPointerException("bytes");
43-
}
4447
this.bytes = bytes;
4548
setFileName(fileName);
4649
}
47-
50+
4851
@Override
4952
protected void sendData(OutputStream out) throws IOException {
5053
out.write(bytes);

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,37 @@ public class FilePart extends AbstractFilePart {
3131
private final File file;
3232

3333
public FilePart(String name, File file) {
34-
this(name, file, null, null);
34+
this(name, file, null);
3535
}
3636

3737
public FilePart(String name, File file, String contentType) {
38-
this(name, file, null, contentType, null);
38+
this(name, file, contentType, null);
3939
}
4040

4141
public FilePart(String name, File file, String contentType, String charset) {
42-
this(name, file, null, contentType, charset, null);
42+
this(name, file, contentType, charset, null);
4343
}
4444

4545
public FilePart(String name, File file, String contentType, String charset, String fileName) {
46-
this(name, file, null, contentType, charset, fileName);
46+
this(name, file, contentType, charset, fileName, null);
4747
}
4848

4949
public FilePart(String name, File file, String contentType, String charset, String fileName, String contentId) {
50-
super(name, contentType, charset, contentId);
51-
this.file = file;
52-
if (file == null) {
50+
this(name, file, contentType, charset, fileName, contentId, null);
51+
}
52+
53+
public FilePart(String name, File file, String contentType, String charset, String fileName, String contentId, String transferEncoding) {
54+
super(name, contentType, charset, contentId, transferEncoding);
55+
if (file == null)
5356
throw new NullPointerException("file");
54-
}
55-
if (!file.isFile()) {
57+
if (!file.isFile())
5658
throw new IllegalArgumentException("File is not a normal file " + file.getAbsolutePath());
57-
}
58-
if (!file.canRead()) {
59+
if (!file.canRead())
5960
throw new IllegalArgumentException("File is not readable " + file.getAbsolutePath());
60-
}
61+
this.file = file;
6162
setFileName(fileName != null ? fileName : file.getName());
6263
}
63-
64+
6465
@Override
6566
protected void sendData(OutputStream out) throws IOException {
6667
if (getDataLength() == 0) {

src/main/java/com/ning/http/client/multipart/PartBase.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,25 @@ public abstract class PartBase implements Part {
4949
*/
5050
private String dispositionType;
5151

52+
public PartBase(String name, String contentType, String charSet, String contentId) {
53+
this(name, contentType, charSet, contentId, null);
54+
}
55+
5256
/**
5357
* Constructor.
5458
*
5559
* @param name The name of the part, or <code>null</code>
5660
* @param contentType The content type, or <code>null</code>
5761
* @param charSet The character encoding, or <code>null</code>
58-
* @param transferEncoding The transfer encoding, or <code>null</code>
5962
* @param contentId The content id, or <code>null</code>
63+
* @param transferEncoding The transfer encoding, or <code>null</code>
6064
*/
61-
public PartBase(String name, String contentType, String charSet, String transferEncoding, String contentId) {
65+
public PartBase(String name, String contentType, String charSet, String contentId, String transferEncoding) {
6266
this.name = name;
6367
this.contentType = contentType;
6468
this.charSet = charSet;
65-
this.transferEncoding = transferEncoding;
6669
this.contentId = contentId;
70+
this.transferEncoding = transferEncoding;
6771
}
6872

6973
protected void visitStart(PartVisitor visitor, byte[] boundary) throws IOException {

src/main/java/com/ning/http/client/multipart/StringPart.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public StringPart(String name, String value, String charset) {
5858
* the content id
5959
*/
6060
public StringPart(String name, String value, String charset, String contentId) {
61-
62-
super(name, DEFAULT_CONTENT_TYPE, charset == null ? DEFAULT_CHARSET : charset, DEFAULT_TRANSFER_ENCODING, contentId);
61+
super(name, DEFAULT_CONTENT_TYPE, charset == null ? DEFAULT_CHARSET : charset, contentId, DEFAULT_TRANSFER_ENCODING);
6362
if (value == null) {
6463
throw new NullPointerException("value");
6564
}

0 commit comments

Comments
 (0)