You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2010/04/08 19:32:49 UTC
svn commit: r932022 -
/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
Author: olegk
Date: Thu Apr 8 17:32:48 2010
New Revision: 932022
URL: http://svn.apache.org/viewvc?rev=932022&view=rev
Log:
HTTPCLIENT-904: convenience #create methods
Modified:
httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java?rev=932022&r1=932021&r2=932022&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java Thu Apr 8 17:32:48 2010
@@ -52,6 +52,35 @@ public class StringBody extends Abstract
private final byte[] content;
private final Charset charset;
+ /**
+ * @since 4.1
+ */
+ public static StringBody create(
+ final String text,
+ final String mimeType,
+ final Charset charset) throws IllegalArgumentException {
+ try {
+ return new StringBody(text, mimeType, charset);
+ } catch (UnsupportedEncodingException ex) {
+ throw new IllegalArgumentException("Charset " + charset + " is not supported", ex);
+ }
+ }
+
+ /**
+ * @since 4.1
+ */
+ public static StringBody create(
+ final String text, final Charset charset) throws IllegalArgumentException {
+ return create(text, null, charset);
+ }
+
+ /**
+ * @since 4.1
+ */
+ public static StringBody create(final String text) throws IllegalArgumentException {
+ return create(text, null, null);
+ }
+
public StringBody(
final String text,
final String mimeType,
@@ -67,7 +96,7 @@ public class StringBody extends Abstract
this.charset = charset;
}
- public StringBody(final String text, Charset charset) throws UnsupportedEncodingException {
+ public StringBody(final String text, final Charset charset) throws UnsupportedEncodingException {
this(text, "text/plain", charset);
}