java - Stax parser fails to read files with encoding UTF-16 -


i using stax parser read xml file inside common api in app. api takes inputstream parameter , doing below

public object <commonapi>(inputstream is)   xmlinputfactory inputfactory = xmlinputfactory.newinstance();   xmleventreader reader = inputfactory.createxmleventreader(is);   try{            while (parser.hasnext()) {       xmlevent event = parser.nextevent();       // reaming parsing logic      }    } catch (exception e){       e.printstacktrace();    } } 

the issue works if encoding in xml file utf-8. if utf-16, doesn't read properly..gives following exception

javax.xml.stream.xmlstreamexception: parseerror @ [row,col]:[1,41] message: content not allowed in prolog.

i can't change signature of common api. need operate on inputstream.. suggestions?

use createxmleventreader(inputstream stream, string encoding) utf-16 encoding.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -