From 659a47be1d421fc3a85efafc726892041a63d821 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 8 Apr 2010 17:32:48 +0000 Subject: [PATCH] HTTPCLIENT-904: convenience #create methods git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@932022 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/entity/mime/content/StringBody.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java b/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java index 0e96957fa..81b68777e 100644 --- a/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java +++ b/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java @@ -52,6 +52,35 @@ public class StringBody extends AbstractContentBody { 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 AbstractContentBody { 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); }