hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1051681 - in /httpcomponents/httpclient/trunk/httpmime/src: main/java/org/apache/http/entity/mime/HttpMultipart.java main/java/org/apache/http/entity/mime/MultipartEntity.java test/java/org/apache/http/entity/mime/TestMultipartForm.java
Date Tue, 21 Dec 2010 22:25:45 GMT
Author: sebb
Date: Tue Dec 21 22:25:45 2010
New Revision: 1051681

URL: http://svn.apache.org/viewvc?rev=1051681&view=rev
Log:
Make mode a final field of HttpMultipart

Modified:
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
    httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java?rev=1051681&r1=1051680&r2=1051681&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
Tue Dec 21 22:25:45 2010
@@ -99,9 +99,18 @@ public class HttpMultipart {
     private final String boundary;
     private final List<FormBodyPart> parts;
 
-    private HttpMultipartMode mode;
+    private final HttpMultipartMode mode;
 
-    public HttpMultipart(final String subType, final Charset charset, final String boundary)
{
+    /**
+     * Creates an instance with the specified settings.
+     * 
+     * @param subType mime subtype - must not be {@code null}
+     * @param charset the character set to use. May be {@code null}, in which case {@link
MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used.
+     * @param boundary to use  - must not be {@code null}
+     * @param mode the mode to use
+     * @throws IllegalArgumentException if charset is null or boundary is null
+     */
+    public HttpMultipart(final String subType, final Charset charset, final String boundary,
HttpMultipartMode mode) {
         super();
         if (subType == null) {
             throw new IllegalArgumentException("Multipart subtype may not be null");
@@ -113,7 +122,20 @@ public class HttpMultipart {
         this.charset = charset != null ? charset : MIME.DEFAULT_CHARSET;
         this.boundary = boundary;
         this.parts = new ArrayList<FormBodyPart>();
-        this.mode = HttpMultipartMode.STRICT;
+        this.mode = mode;
+    }
+
+    /**
+     * Creates an instance with the specified settings.
+     * Mode is set to {@link HttpMultipartMode#STRICT}
+     * 
+     * @param subType mime subtype - must not be {@code null}
+     * @param charset the character set to use. May be {@code null}, in which case {@link
MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used.
+     * @param boundary to use  - must not be {@code null}
+     * @throws IllegalArgumentException if charset is null or boundary is null
+     */
+    public HttpMultipart(final String subType, final Charset charset, final String boundary)
{
+        this(subType, charset, boundary, HttpMultipartMode.STRICT);
     }
 
     public HttpMultipart(final String subType, final String boundary) {
@@ -132,10 +154,6 @@ public class HttpMultipart {
         return this.mode;
     }
 
-    public void setMode(final HttpMultipartMode mode) {
-        this.mode = mode;
-    }
-
     public List<FormBodyPart> getBodyParts() {
         return this.parts;
     }

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java?rev=1051681&r1=1051680&r2=1051681&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
Tue Dec 21 22:25:45 2010
@@ -60,6 +60,12 @@ public class MultipartEntity implements 
     private long length;
     private volatile boolean dirty; // used to decide whether to recalculate length
 
+    /**
+     * Creates an instance using the specified parameters
+     * @param mode the mode to use, may be {@code null}, in which case {@link HttpMultipartMode#STRICT}
is used
+     * @param boundary the boundary string, may be {@code null}, in which case {@link #generateBoundary()}
is invoked to create the string
+     * @param charset the character set to use, may be {@code null}, in which case {@link
MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used.
+     */
     public MultipartEntity(
             HttpMultipartMode mode,
             String boundary,
@@ -68,21 +74,28 @@ public class MultipartEntity implements 
         if (boundary == null) {
             boundary = generateBoundary();
         }
-        this.multipart = new HttpMultipart("form-data", charset, boundary);
+        if (mode == null) {
+            mode = HttpMultipartMode.STRICT;
+        }
+        this.multipart = new HttpMultipart("form-data", charset, boundary, mode);
         this.contentType = new BasicHeader(
                 HTTP.CONTENT_TYPE,
                 generateContentType(boundary, charset));
         this.dirty = true;
-        if (mode == null) {
-            mode = HttpMultipartMode.STRICT;
-        }
-        this.multipart.setMode(mode);
     }
 
+    /**
+     * Creates an instance using the specified {@link HttpMultipartMode} mode.
+     * Boundary and charset are set to {@code null}.
+     * @param mode the desired mode
+     */
     public MultipartEntity(final HttpMultipartMode mode) {
         this(mode, null, null);
     }
 
+    /**
+     * Creates an instance using mode {@link HttpMultipartMode#STRICT}
+     */
     public MultipartEntity() {
         this(HttpMultipartMode.STRICT, null, null);
     }

Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java?rev=1051681&r1=1051680&r2=1051681&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
Tue Dec 21 22:25:45 2010
@@ -151,7 +151,7 @@ public class TestMultipartForm {
             writer.close();
         }
 
-        HttpMultipart multipart = new HttpMultipart("form-data", "foo");
+        HttpMultipart multipart = new HttpMultipart("form-data", null, "foo", HttpMultipartMode.STRICT);
         FormBodyPart p1 = new FormBodyPart(
                 "field1",
                 new FileBody(tmpfile));
@@ -166,8 +166,6 @@ public class TestMultipartForm {
         multipart.addBodyPart(p2);
         multipart.addBodyPart(p3);
 
-        multipart.setMode(HttpMultipartMode.STRICT);
-
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         multipart.writeTo(out);
         out.close();
@@ -235,7 +233,7 @@ public class TestMultipartForm {
             writer.close();
         }
 
-        HttpMultipart multipart = new HttpMultipart("form-data", Charset.forName("UTF-8"),
"foo");
+        HttpMultipart multipart = new HttpMultipart("form-data", Charset.forName("UTF-8"),
"foo", HttpMultipartMode.BROWSER_COMPATIBLE);
         FormBodyPart p1 = new FormBodyPart(
                 "field1",
                 new InputStreamBody(new FileInputStream(tmpfile), s1 + ".tmp"));
@@ -246,8 +244,6 @@ public class TestMultipartForm {
         multipart.addBodyPart(p1);
         multipart.addBodyPart(p2);
 
-        multipart.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
-
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         multipart.writeTo(out);
         out.close();



Mime
View raw message