hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1709814 - /httpcomponents/httpclient/branches/4.5.x/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
Date Wed, 21 Oct 2015 12:34:14 GMT
Author: olegk
Date: Wed Oct 21 12:34:14 2015
New Revision: 1709814

URL: http://svn.apache.org/viewvc?rev=1709814&view=rev
Log:
MultipartFormEntity#getContent implementation
Contributed by Slikey <trusted at kevin-carstens.de>

Modified:
    httpcomponents/httpclient/branches/4.5.x/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java

Modified: httpcomponents/httpclient/branches/4.5.x/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java?rev=1709814&r1=1709813&r2=1709814&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/httpmime/src/main/java/org/apache/http/entity/mime/MultipartFormEntity.java
Wed Oct 21 12:34:14 2015
@@ -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 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