HTTPCLIENT-1832: Added content length parameter to InputStreamBody constructor

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1787772 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2017-03-20 13:48:18 +00:00
parent d07ee6fbc7
commit db97c706d4
1 changed files with 10 additions and 1 deletions

View File

@ -45,6 +45,7 @@ public class InputStreamBody extends AbstractContentBody {
private final InputStream in;
private final String filename;
private final long contentLength;
public InputStreamBody(final InputStream in, final String filename) {
this(in, ContentType.DEFAULT_BINARY, filename);
@ -54,10 +55,18 @@ public class InputStreamBody extends AbstractContentBody {
* @since 4.3
*/
public InputStreamBody(final InputStream in, final ContentType contentType, final String filename) {
this(in, contentType, filename, -1);
}
/**
* @since 4.6
*/
public InputStreamBody(final InputStream in, final ContentType contentType, final String filename, final long contentLength) {
super(contentType);
Args.notNull(in, "Input stream");
this.in = in;
this.filename = filename;
this.contentLength = contentLength >= 0 ? contentLength : -1;
}
/**
@ -93,7 +102,7 @@ public class InputStreamBody extends AbstractContentBody {
@Override
public long getContentLength() {
return -1;
return this.contentLength;
}
@Override