hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1154488 - in /httpcomponents/httpcore/trunk: httpcore-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java httpcore/src/main/java/org/apache/http/entity/StringEntity.java
Date Sat, 06 Aug 2011 11:07:14 GMT
Author: olegk
Date: Sat Aug  6 11:07:13 2011
New Revision: 1154488

URL: http://svn.apache.org/viewvc?rev=1154488&view=rev
Log:
Added convenience create methods

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

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=1154488&r1=1154487&r2=1154488&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
Sat Aug  6 11:07:13 2011
@@ -57,6 +57,71 @@ public class NStringEntity extends Abstr
     protected final ByteBuffer buffer;
 
     /**
+     * Creates a NStringEntity with the specified content and content type.
+     *
+     * @param string content to be used. Not {@code null}.
+     * @param contentType content type to be used. May be {@code null}, in which case the
default
+     *   MIME type {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain" and the default charset
+     *   {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1" are assumed.
+     *
+     * @throws IllegalArgumentException if the string parameter is null or if the charset
+     *   specified in the CotnentType is not supported.
+     *
+     * @since 4.2
+     */
+    public static NStringEntity create(final String string, final ContentType contentType)
{
+        try {
+            return new NStringEntity(string, contentType);
+        } catch (UnsupportedEncodingException ex) {
+            throw new IllegalArgumentException(ex.getMessage(), ex);
+        }
+    }
+
+    /**
+     * Creates a StringEntity with the specified content and charset. The mime type defaults
+     * to {@link HTTP#PLAIN_TEXT_TYPE} i.e. "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#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1"
+     *
+     * @throws IllegalArgumentException if the string parameter is null or if the charset
+     *   specified in the CotnentType is not supported.
+     *
+     * @since 4.2
+     */
+    public static NStringEntity create(
+            final String string, final String charset) {
+        return create(string, ContentType.create(HTTP.PLAIN_TEXT_TYPE, charset));
+    }
+
+    /**
+     * Creates a StringEntity with the specified content and charset. The charset defaults
to
+     * {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1". The mime type defaults to
+     * {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain".
+     *
+     * @param string content to be used. Not {@code null}.
+     *
+     * @throws IllegalArgumentException if the string parameter is null
+     *
+     * @since 4.2
+     */
+    public static NStringEntity create(final String string) {
+        return create(string, ContentType.DEFAULT_TEXT);
+    }
+
+    /**
+     * Creates a NStringEntity with the specified content and content type.
+     *
+     * @param string content to be used. Not {@code null}.
+     * @param contentType content type to be used. May be {@code null}, in which case the
default
+     *   MIME type {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain" and the default charset
+     *   {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1" are assumed.
+     *
+     * @throws IllegalArgumentException if the string parameter is null
+     * @throws UnsupportedEncodingException if the charset specified in the CotnentType
+     *   is not supported.
+     *
      * @since 4.2
      */
     public NStringEntity(final String s, final ContentType contentType)
@@ -75,11 +140,32 @@ public class NStringEntity extends Abstr
         }
     }
 
+    /**
+     * Creates a NStringEntity with the specified content and charset. The mime type defaults
+     * to {@link HTTP#PLAIN_TEXT_TYPE} i.e. "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#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1"
+     *
+     * @throws IllegalArgumentException if the string parameter is null
+     * @throws UnsupportedEncodingException if the charset is not supported.
+     */
     public NStringEntity(final String s, final String charset)
             throws UnsupportedEncodingException {
         this(s, ContentType.create(HTTP.PLAIN_TEXT_TYPE, charset));
     }
 
+    /**
+     * Creates a StringEntity with the specified content and charset. The charset defaults
to
+     * {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1". The mime type defaults to
+     * {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain".
+     *
+     * @param string content to be used. Not {@code null}.
+     *
+     * @throws IllegalArgumentException if the string parameter is null
+     * @throws UnsupportedEncodingException if the default HTTP charset is not supported.
+     */
     public NStringEntity(final String s) throws UnsupportedEncodingException {
         this(s, ContentType.DEFAULT_TEXT);
     }

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=1154488&r1=1154487&r2=1154488&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
Sat Aug  6 11:07:13 2011
@@ -55,9 +55,65 @@ public class StringEntity extends Abstra
      *   MIME type {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain" and the default charset
      *   {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1" are assumed.
      *
+     * @throws IllegalArgumentException if the string parameter is null or if the charset
+     *   specified in the CotnentType is not supported.
+     *
+     * @since 4.2
+     */
+    public static StringEntity create(final String string, final ContentType contentType)
{
+        try {
+            return new StringEntity(string, contentType);
+        } catch (UnsupportedEncodingException ex) {
+            throw new IllegalArgumentException(ex.getMessage(), ex);
+        }
+    }
+
+    /**
+     * Creates a StringEntity with the specified content and charset. The mime type defaults
+     * to {@link HTTP#PLAIN_TEXT_TYPE} i.e. "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#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1"
+     *
+     * @throws IllegalArgumentException if the string parameter is null or if the charset
+     *   specified in the CotnentType is not supported.
+     *
      * @since 4.2
+     */
+    public static StringEntity create(
+            final String string, final String charset) {
+        return create(string, ContentType.create(HTTP.PLAIN_TEXT_TYPE, charset));
+    }
+
+    /**
+     * Creates a StringEntity with the specified content and charset. The charset defaults
to
+     * {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1". The mime type defaults to
+     * {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain".
+     *
+     * @param string content to be used. Not {@code null}.
      *
      * @throws IllegalArgumentException if the string parameter is null
+     *
+     * @since 4.2
+     */
+    public static StringEntity create(final String string) {
+        return create(string, ContentType.DEFAULT_TEXT);
+    }
+
+    /**
+     * Creates a StringEntity with the specified content and content type.
+     *
+     * @param string content to be used. Not {@code null}.
+     * @param contentType content type to be used. May be {@code null}, in which case the
default
+     *   MIME type {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain" and the default charset
+     *   {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1" are assumed.
+     *
+     * @throws IllegalArgumentException if the string parameter is null
+     * @throws UnsupportedEncodingException if the charset specified in the CotnentType
+     *   is not supported.
+     *
+     * @since 4.2
      */
     public StringEntity(final String string, final ContentType contentType)
             throws UnsupportedEncodingException {
@@ -79,8 +135,10 @@ public class StringEntity extends Abstra
      * Creates a StringEntity with the specified content, mimetype and charset
      *
      * @param string content to be used. Not {@code null}.
-     * @param mimeType mime type to be used. May be {@code null}, in which case the default
is {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain"
-     * @param charset character set to be used. May be {@code null}, in which case the default
is {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1"
+     * @param mimeType mime type to be used. May be {@code null}, in which case the default
+     *   is {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain"
+     * @param charset character set to be used. May be {@code null}, in which case the default
+     *   is {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1"
      *
      * @since 4.1
      * @throws IllegalArgumentException if the string parameter is null
@@ -105,15 +163,15 @@ public class StringEntity extends Abstra
     }
 
     /**
-     * Creates a StringEntity with the specified content and charset.
-     * <br/>
-     * The mime type defaults to {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain".
+     * Creates a StringEntity with the specified content and charset. The mime type defaults
+     * to {@link HTTP#PLAIN_TEXT_TYPE} i.e. "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#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1"
      *
      * @throws IllegalArgumentException if the string parameter is null
+     * @throws UnsupportedEncodingException if the charset is not supported.
      */
     public StringEntity(final String string, final String charset)
             throws UnsupportedEncodingException {
@@ -121,15 +179,14 @@ public class StringEntity extends Abstra
     }
 
     /**
-     * Creates a StringEntity with the specified content and charset.
-     * <br/>
-     * The charset defaults to {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1".
-     * <br/>
-     * The mime type defaults to {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain".
+     * Creates a StringEntity with the specified content and charset. The charset defaults
to
+     * {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1". The mime type defaults to
+     * {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain".
      *
      * @param string content to be used. Not {@code null}.
      *
      * @throws IllegalArgumentException if the string parameter is null
+     * @throws UnsupportedEncodingException if the default HTTP charset is not supported.
      */
     public StringEntity(final String string)
             throws UnsupportedEncodingException {



Mime
View raw message