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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -