You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2015/10/21 14:34:34 UTC
svn commit: r1709815 -
/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
Author: olegk
Date: Wed Oct 21 12:34:34 2015
New Revision: 1709815
URL: http://svn.apache.org/viewvc?rev=1709815&view=rev
Log:
MultipartFormEntity#getContent implementation
Contributed by Slikey <trusted at kevin-carstens.de>
Modified:
httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java?rev=1709815&r1=1709814&r2=1709815&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java Wed Oct 21 12:34:34 2015
@@ -27,10 +27,13 @@
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;
@@ -93,8 +96,15 @@ class MultipartFormEntity implements Htt
@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