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:
parent
8e6ab0bdb8
commit
09cefc2b89
|
@ -27,16 +27,19 @@
|
||||||
|
|
||||||
package org.apache.http.entity.mime;
|
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.Header;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.apache.http.message.BasicHeader;
|
import org.apache.http.message.BasicHeader;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
class MultipartFormEntity implements HttpEntity {
|
class MultipartFormEntity implements HttpEntity {
|
||||||
|
|
||||||
|
@ -94,8 +97,15 @@ class MultipartFormEntity implements HttpEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getContent() throws IOException {
|
public InputStream getContent() throws IOException {
|
||||||
throw new UnsupportedOperationException(
|
if (this.contentLength < 0) {
|
||||||
"Multipart form entity does not implement #getContent()");
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue