hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1709815 - /httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
Date Wed, 21 Oct 2015 12:34:34 GMT
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



Mime
View raw message