XMLEntityHandler.EntityReader declReader = new XMLDeclReader(entityHandler, errorReporter, sendCharDataAsCharArray, data, stringPool);
int encoding = prescanXMLDeclOrTextDecl(declReader, xmlDecl);
if (encoding != -1) {
String encname = stringPool.orphanString(encoding);
String enc = encname.toUpperCase();
if ("ISO-10646-UCS-2".equals(enc)) throw new UnsupportedEncodingException(encname);
if ("ISO-10646-UCS-4".equals(enc)) throw new UnsupportedEncodingException(encname);
if ("UTF-16".equals(enc)) throw new UnsupportedEncodingException(encname);
String javaencname = MIME2Java.convert(enc);
if (null == javaencname) {
// Not supported
if (allowJavaEncodingName) {
javaencname = encname;
} else {
throw new UnsupportedEncodingException(encname);
}
}
try {
data.rewind();
if ("UTF-8".equalsIgnoreCase(javaencname) || "UTF8".equalsIgnoreCase(javaencname)) {
reader = readerFactory.createUTF8Reader(entityHandler, errorReporter, sendCharDataAsCharArray, data, stringPool);
} else {
reader = readerFactory.createCharReader(entityHandler, errorReporter, sendCharDataAsCharArray,
new InputStreamReader(data, javaencname), stringPool);
}
} catch (UnsupportedEncodingException e) {
throw new UnsupportedEncodingException(encname);
} catch (Exception e) {
e.printStackTrace(); // Internal Error
}
} else {
data.rewind();