hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1327643 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/nio/entity/ httpcore/src/main/java/org/apache/http/entity/ httpcore/src/test/java/org/apache/http/entity/
Date Wed, 18 Apr 2012 19:38:16 GMT
Author: olegk
Date: Wed Apr 18 19:38:13 2012
New Revision: 1327643

URL: http://svn.apache.org/viewvc?rev=1327643&view=rev
Log:
HTTPCORE-297: Extra StringEntity and NStringEntity constructors
Contributed by Gary D. Gregory <garydgregory at gmail.com>

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java?rev=1327643&r1=1327642&r2=1327643&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
Wed Apr 18 19:38:13 2012
@@ -112,6 +112,22 @@ public class NStringEntity extends Abstr
     }
 
     /**
+     * Creates a NStringEntity with the specified content and charset. The MIME type defaults
+     * to "text/plain".
+     *
+     * @param string content to be used. Not {@code null}.
+     * @param charset character set to be used. May be {@code null}, in which case the default
+     *   is {@link HTTP#DEF_CONTENT_CHARSET} is assumed
+     *
+     * @throws IllegalArgumentException if the string parameter is null
+     * 
+     * @since 4.2
+     */
+    public NStringEntity(final String s, final Charset charset) {
+        this(s, ContentType.create(ContentType.TEXT_PLAIN.getMimeType(), charset));
+    }
+
+    /**
      * Creates a NStringEntity with the specified content. The content type defaults to
      * {@link ContentType#TEXT_PLAIN}.
      *

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java?rev=1327643&r1=1327642&r2=1327643&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java
Wed Apr 18 19:38:13 2012
@@ -66,9 +66,6 @@ public class StringEntity extends Abstra
             throw new IllegalArgumentException("Source string may not be null");
         }
         Charset charset = contentType != null ? contentType.getCharset() : null;
-        if (charset == null) {
-            charset = HTTP.DEF_CONTENT_CHARSET;
-        }
         try {
             this.content = string.getBytes(charset.name());
         } catch (UnsupportedEncodingException ex) {
@@ -128,6 +125,22 @@ public class StringEntity extends Abstra
     }
 
     /**
+     * Creates a StringEntity with the specified content and charset. The MIME type defaults
+     * to "text/plain".
+     *
+     * @param string content to be used. Not {@code null}.
+     * @param charset character set to be used. May be {@code null}, in which case the default
+     *   is {@link HTTP#DEF_CONTENT_CHARSET} is assumed
+     *
+     * @throws IllegalArgumentException if the string parameter is null
+     * 
+     * @since 4.2
+     */
+    public StringEntity(final String string, final Charset charset) {
+        this(string, ContentType.create(ContentType.TEXT_PLAIN.getMimeType(), charset));
+    }
+
+    /**
      * Creates a StringEntity with the specified content. The content type defaults to
      * {@link ContentType#TEXT_PLAIN}.
      *

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java?rev=1327643&r1=1327642&r2=1327643&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java
Wed Apr 18 19:38:13 2012
@@ -35,7 +35,6 @@ import org.junit.Test;
 
 /**
  * Unit tests for {@link StringEntity}.
- *
  */
 public class TestStringEntity {
 
@@ -70,6 +69,9 @@ public class TestStringEntity {
         httpentity = new StringEntity(s, Consts.ASCII.name());
         Assert.assertEquals("text/plain; charset=US-ASCII",
                 httpentity.getContentType().getValue());
+        httpentity = new StringEntity(s, Consts.ASCII);
+        Assert.assertEquals("text/plain; charset=US-ASCII",
+                httpentity.getContentType().getValue());
         httpentity = new StringEntity(s);
         Assert.assertEquals("text/plain; charset=ISO-8859-1",
                 httpentity.getContentType().getValue());



Mime
View raw message