Index: httpcore/src/main/java/org/apache/http/entity/StringEntity.java =================================================================== --- httpcore/src/main/java/org/apache/http/entity/StringEntity.java (revision 1570502) +++ httpcore/src/main/java/org/apache/http/entity/StringEntity.java (working copy) @@ -27,18 +27,17 @@ package org.apache.http.entity; +import org.apache.http.annotation.NotThreadSafe; +import org.apache.http.protocol.HTTP; +import org.apache.http.util.Args; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; -import org.apache.http.annotation.NotThreadSafe; -import org.apache.http.protocol.HTTP; -import org.apache.http.util.Args; - /** * A self contained, repeatable entity that obtains its content from * a {@link String}. @@ -83,21 +82,23 @@ * 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#DEF_CONTENT_CHARSET} i.e. "ISO-8859-1" - * @throws UnsupportedEncodingException If the named charset is not supported. * * @since 4.1 * @throws IllegalArgumentException if the string parameter is null + * @throws UnsupportedCharsetException Thrown when the named charset is not available in + * this instance of the Java virtual machine * * @deprecated (4.1.3) use {@link #StringEntity(String, ContentType)} */ @Deprecated public StringEntity( - final String string, final String mimeType, final String charset) throws UnsupportedEncodingException { + final String string, final String mimeType, final String charset) + throws UnsupportedCharsetException{ super(); Args.notNull(string, "Source string"); final String mt = mimeType != null ? mimeType : HTTP.PLAIN_TEXT_TYPE; final String cs = charset != null ? charset :HTTP.DEFAULT_CONTENT_CHARSET; - this.content = string.getBytes(cs); + this.content = string.getBytes(Charset.forName(cs)); setContentType(mt + HTTP.CHARSET_PARAM + cs); } @@ -141,10 +142,11 @@ * @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. + * @throws UnsupportedCharsetException Thrown when the named charset is not available in + * this instance of the Java virtual machine */ public StringEntity(final String string) - throws UnsupportedEncodingException { + throws UnsupportedCharsetException { this(string, ContentType.DEFAULT_TEXT); }