HTTPCLIENT-2066 Provide ByteArrayBody constructors w/o filename parameter
This closes #319
This commit is contained in:
parent
0926f1e07a
commit
af2cc82e82
|
@ -56,11 +56,22 @@ public class ByteArrayBody extends AbstractContentBody {
|
|||
*/
|
||||
public ByteArrayBody(final byte[] data, final ContentType contentType, final String filename) {
|
||||
super(contentType);
|
||||
Args.notNull(data, "byte[]");
|
||||
this.data = data;
|
||||
this.data = Args.notNull(data, "data");
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public constructor that creates a new ByteArrayBody.
|
||||
*
|
||||
* @param contentType the {@link ContentType}
|
||||
* @param data the array of byte.
|
||||
*
|
||||
* @since 5.2
|
||||
*/
|
||||
public ByteArrayBody(final byte[] data, final ContentType contentType) {
|
||||
this(data, contentType, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ByteArrayBody.
|
||||
*
|
||||
|
|
|
@ -155,7 +155,7 @@ public class MultipartEntityBuilder {
|
|||
|
||||
public MultipartEntityBuilder addBinaryBody(
|
||||
final String name, final byte[] b) {
|
||||
return addBinaryBody(name, b, ContentType.DEFAULT_BINARY, null);
|
||||
return addPart(name, new ByteArrayBody(b, ContentType.DEFAULT_BINARY));
|
||||
}
|
||||
|
||||
public MultipartEntityBuilder addBinaryBody(
|
||||
|
|
|
@ -70,13 +70,15 @@ public class TestMultipartEntityBuilder {
|
|||
.addBinaryBody("p2", new File("stuff"))
|
||||
.addBinaryBody("p3", new byte[]{})
|
||||
.addBinaryBody("p4", new ByteArrayInputStream(new byte[]{}))
|
||||
.addBinaryBody("p5", new ByteArrayInputStream(new byte[]{}), ContentType.DEFAULT_BINARY, "filename")
|
||||
.buildEntity();
|
||||
Assert.assertNotNull(entity);
|
||||
final List<MultipartPart> bodyParts = entity.getMultipart().getParts();
|
||||
Assert.assertNotNull(bodyParts);
|
||||
Assert.assertEquals(4, bodyParts.size());
|
||||
Assert.assertEquals(5, bodyParts.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMultipartCustomContentType() throws Exception {
|
||||
final MultipartFormEntity entity = MultipartEntityBuilder.create()
|
||||
|
|
Loading…
Reference in New Issue