HTTPCLIENT-904: convenience #create methods

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@932022 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2010-04-08 17:32:48 +00:00
parent 42b6aa2f93
commit 659a47be1d
1 changed files with 30 additions and 1 deletions

View File

@ -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);
}