MultipartFormEntity#getContent implementation

Contributed by Slikey <trusted at kevin-carstens.de>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1709814 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2015-10-21 12:34:14 +00:00
parent 8e6ab0bdb8
commit 09cefc2b89
1 changed files with 16 additions and 6 deletions

View File

@ -27,16 +27,19 @@
package org.apache.http.entity.mime;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.ContentTooLongException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@SuppressWarnings("deprecation")
class MultipartFormEntity implements HttpEntity {
@ -94,8 +97,15 @@ class MultipartFormEntity implements HttpEntity {
@Override
public InputStream getContent() throws IOException {
throw new UnsupportedOperationException(
"Multipart form entity does not implement #getContent()");
if (this.contentLength < 0) {
throw new ContentTooLongException("Content length is unknown");
} else if (this.contentLength > 25 * 1024) {
throw new ContentTooLongException("Content length is too long: " + this.contentLength);
}
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
writeTo(outstream);
outstream.flush();
return new ByteArrayInputStream(outstream.toByteArray());
}
@Override