Applies to:
NA
Description:
Occurs when invoking getContent() method on a bodypart that contains text data.
Cause:
Textual bodyparts (i.e., bodyparts whose type is “text/plain”, “text/html”, or “text/xml”) return Unicode String objects when getContent() is used. Typically, such bodyparts internally hold their textual data in some non Unicode charset. JavaMail (through the corresponding DataContentHandler) attempts to convert that data into a Unicode string. The underlying JDK’s charset converters are used to do this. If the JDK does not support a particular charset, then the UnsupportedEncodingException is thrown.
JAVA-Mail "java.nio.charset.spi" tomcat, axis2 "unsupportedencodingexception" "text/xml", bodypart getcontent, bodypart getcontent to string, bodypart getcontent() string, charset not support unsupportedencodingexception, charsetprovider example, charsetprovider glassfish, charsetprovider java jvm, charsetprovider java weblogic services, charsetprovider jetty, convert getcontent java, dy, ejb java.nio.charset.spi.charsetprovider, getcontent 'us-ascii' exception, getcontent for unicode java, getcontent javamail, getcontent unsupportedencodingexception, glassfish meta-inf.services.charset, gwt unsupportedencodingexception, how to handle unsupportedcharset in javamail, how to solve unsupported exception of getcontent method, j, java additional charsetprovider, java find unsupported charset and convert, java mail convert charset, java mail getcontent unsupported exception, java mail getcontent unsupportedencodingexception, java mail message get content string unsupportedencodingexception, java mail text-html unsupported, java mail unsupported encoding exception text/html, java mail unsupportedencodingexception: text/html, java part getcontent() convert to byte[], java unsupported encoding text/xml, java unsupportedencoding "us-ascii", java unsupportedencodingexception getcontent, java unsupportedencodingexception plain, java unsupportedencodingexception us-ascii, java unsupportedencodingexception: text/html, javamail bodypart getcontent, javamail getconent null, javamail getcontent proper charset, javamail getcontent unsupportedencodingexception, javamail getcontent() charset, javamail unsupported charset handling, javamail unsupported encoding exception getcontent, javamail unsupportedencodingexception getcontent, javamail unsupportedencodingexception solutions, javamail unsupportedencodingexception: text/html, javax.mail.bodypart.getcontent encoding, javax.mail.bodypart.getcontent encodingexception, javax.xml.stream unsupported encoding 1252 -axis2, jetty unsupportedencodingexception jre jdk, lrm-00118: syntax error at '=' at the end of input, oracharset forname, part getcontent unsupportedencodingexception, solution for unsupported exception, solve unsupportedencodingexception, tinea capitis, tomcat charsetprovider tutorial, unsupported coding exception text/html, unsupported encoding: text/html, unsupportedencodingexception "text/html" mail, unsupportedencodingexception : text/html in java, unsupportedencodingexception bodypart getcontent, unsupportedencodingexception getcontent, unsupportedencodingexception getcontent javamail, unsupportedencodingexception gwt, unsupportedencodingexception gwt jetty, unsupportedencodingexception in getcontent(), unsupportedencodingexception java mail, unsupportedencodingexception javamail, unsupportedencodingexception javamail getcontent, unsupportedencodingexception oracle database, unsupportedencodingexception solution, unsupportedencodingexception: cp0, unsupportedencodingexception: text/html, unsupportedencodingexception: text/plain, what is the charset for html character encoding in java in bodypart, when is unsupportedencodingexception
In this case, you can use the getInputStream() method to retrieve the content as a stream of bytes. For example:
String s;
if (part.isMimeType(“text/plain”)) {
try {
s = part.getContent();
} catch (UnsupportedEncodingException uex) {
InputStream is = part.getInputStream();
/*
* Read the input stream into a byte array.
* Choose a charset in some heuristic manner, use
* that charset in the java.lang.String constructor
* to convert the byte array into a String.
*/
s = convert_to_string(is);
} catch (Exception ex) {
// Handle other exceptions appropriately
}
}
There are some commonly used charsets that the JDK does not yet support.
You can also add an alias for an existing charset already supported by the JDK so that it will be known by an additional name. You can create a charset provider for the “bad” charset name that simply redirects to an existing charset provider; see the following code. Create an appropriate CharsetProvider subclass and include it along with the META-INF/services file and the JDK will find it. Obviously you could get significantly more clever and redirect all unknown charsets to “us-ascii”, for instance.
==> TestCharsetProvider.java < ==
import java.nio.charset.*;
import java.nio.charset.spi.*;
import java.util.*;
public class TestCharsetProvider extends CharsetProvider {
private static final String badCharset = "cp-1252";
private static final String goodCharset = "cp1252";
public Charset charsetForName(String charset) {
if (charset.equals(badCharset))
return Charset.forName(goodCharset);
return null;
}
public Iterator charsets() {
return null;
}
}
==> META-INF/services/java.nio.charset.spi.CharsetProvider <==
TestCharsetProvider